From: John David Anglin Date: Thu, 27 Oct 2016 00:16:01 +0000 (-0700) Subject: getprogname: port to HP-UX X-Git-Tag: v1.0~6576 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=3c72272268021349cbc9a442fe033e7ba13a0c17;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index 80e8fbe984..50986efe74 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2016-10-26 John David Anglin + + 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 Update doc about target platforms. diff --git a/lib/getprogname.c b/lib/getprogname.c index 47995cdc0e..ad5f878ff7 100644 --- a/lib/getprogname.c +++ b/lib/getprogname.c @@ -36,6 +36,13 @@ # include #endif +#ifdef __hpux +# include +# include +# include +# include +#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 6cb664315f..7c2b87250d 100644 --- a/tests/test-getprogname.c +++ b/tests/test-getprogname.c @@ -20,7 +20,11 @@ #include #include -#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)