]> Savannah Git Hosting - gnulib.git/commitdiff
getprogname: port to HP-UX
authorJohn David Anglin <dave.anglin@bell.net>
Thu, 27 Oct 2016 00:16:01 +0000 (17:16 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 27 Oct 2016 00:17:36 +0000 (17:17 -0700)
See Bug#24805.
* lib/getprogname.c (getprogname) [__hpux]: Port.
* tests/test-getprogname.c (STREQ) [__hpux]:
Special-case for HP-UX limitations on program name length.

ChangeLog
lib/getprogname.c
tests/test-getprogname.c

index 80e8fbe98499e6de4100a4149f9d20242d142a83..50986efe7462eeb44e8e68d8f852537f6af3169d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2016-10-26  John David Anglin  <dave.anglin@bell.net>
+
+       getprogname: port to HP-UX
+       See Bug#24805.
+       * lib/getprogname.c (getprogname) [__hpux]: Port.
+       * tests/test-getprogname.c (STREQ) [__hpux]:
+       Special-case for HP-UX limitations on program name length.
+
 2016-10-20  Bruno Haible  <bruno@clisp.org>
 
        Update doc about target platforms.
index 47995cdc0efd8dc80c1ea8b09952a6f7a9a8367c..ad5f878ff760d47c704166ccae41a4e22e23d87e 100644 (file)
 # include <sys/ps.h>
 #endif
 
+#ifdef __hpux
+# include <unistd.h>
+# include <sys/param.h>
+# include <sys/pstat.h>
+# include <string.h>
+#endif
+
 #include "dirname.h"
 
 #ifndef HAVE_GETPROGNAME             /* not Mac OS X, FreeBSD, NetBSD, OpenBSD >= 5.4, Cygwin */
@@ -88,6 +95,21 @@ getprogname (void)
         p = "?";
     }
   return p;
+# elif defined __hpux
+  static char *p;
+  static int first = 1;
+  if (first)
+    {
+      first = 0;
+      pid_t pid = getpid ();
+      struct pst_status status;
+      p = (0 < pstat_getproc (&status, sizeof status, 0, pid)
+           ? strdup (status.pst_ucomm)
+           : NULL);
+      if (!p)
+        p = "?";
+    }
+  return p;
 # elif __MVS__                                              /* z/OS */
   /* https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxbd00/rtwgetp.htm */
   static char *p = "?";
index 6cb664315f5a074d42315978591e5029adb3ac06..7c2b87250d473c30c1c5bf9c9b7ad91738cb6764 100644 (file)
 #include <string.h>
 #include <assert.h>
 
-#define STREQ(a, b) (strcmp (a, b) == 0)
+#ifdef __hpux
+# define STREQ(a, b) (strncmp (a, b, 14) == 0)
+#else
+# define STREQ(a, b) (strcmp (a, b) == 0)
+#endif
 
 int
 main (void)