Ha! And I was just last week defending HP-UX as still being a relevant platform for GNU applications! See:

http://lists.gnu.org/archive/html/bug-gnulib/2016-10/msg00116.html

Anyway, thanks for the port to HP-UX. I installed the attached patch into Gnulib and it should appear in the next grep release, so I am somewhat boldly marking this bug as done.
From 16e1d6a4c8f3adfe5e14fbf7251462bf4633272d Mon Sep 17 00:00:00 2001
From: John David Anglin <dave.anglin@bell.net>
Date: Wed, 26 Oct 2016 17:16:01 -0700
Subject: [PATCH] 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.
---
 ChangeLog                |  8 ++++++++
 lib/getprogname.c        | 22 ++++++++++++++++++++++
 tests/test-getprogname.c |  6 +++++-
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 80e8fbe..50986ef 100644
--- 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.
diff --git a/lib/getprogname.c b/lib/getprogname.c
index 47995cd..ad5f878 100644
--- a/lib/getprogname.c
+++ b/lib/getprogname.c
@@ -36,6 +36,13 @@
 # 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 = "?";
diff --git a/tests/test-getprogname.c b/tests/test-getprogname.c
index 6cb6643..7c2b872 100644
--- a/tests/test-getprogname.c
+++ b/tests/test-getprogname.c
@@ -20,7 +20,11 @@
 #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)
-- 
2.7.4

Reply via email to