Mercurial > gnulib
changeset 18427:7768cdb94837
getprogname: port to AIX
* lib/getprogname.c (getprogname) [_AIX]: Use getpid, getprocs64
and strdup to obtain a short program name string. Using code from
Bruno Haible and an idea from Bastien ROUCARIÈS, in
https://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00249.html
Assaf Gordon reported that this new file would fail to compile on
AIX-7.1 32bit.
author | Jim Meyering <meyering@fb.com> |
---|---|
date | Wed, 21 Sep 2016 21:15:59 -0700 |
parents | f6fbc8de01de |
children | 1a5ae8213cef |
files | ChangeLog lib/getprogname.c |
diffstat | 2 files changed, 36 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Mon Sep 19 09:32:31 2016 -0700 +++ b/ChangeLog Wed Sep 21 21:15:59 2016 -0700 @@ -1,3 +1,13 @@ +2016-09-21 Jim Meyering <meyering@fb.com> + + getprogname: port to AIX + * lib/getprogname.c (getprogname) [_AIX]: Use getpid, getprocs64 + and strdup to obtain a short program name string. Using code from + Bruno Haible and an idea from Bastien ROUCARIÈS, in + https://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00249.html + Assaf Gordon reported that this new file would fail to compile on + AIX-7.1 32bit. + 2016-09-16 Paul Eggert <eggert@cs.ucla.edu> extensions: fix typo in comment
--- a/lib/getprogname.c Mon Sep 19 09:32:31 2016 -0700 +++ b/lib/getprogname.c Wed Sep 21 21:15:59 2016 -0700 @@ -22,6 +22,12 @@ #include <errno.h> /* get program_invocation_name declaration */ #include <stdlib.h> /* get __argv declaration */ +#ifdef _AIX +# include <unistd.h> +# include <procinfo.h> +# include <string.h> +#endif + #include "dirname.h" #ifndef HAVE_GETPROGNAME @@ -41,6 +47,26 @@ # elif HAVE_DECL___ARGV const char *p = __argv && __argv[0] ? __argv[0] : "?"; return last_component (p); +# elif _AIX + /* Idea by Bastien ROUCARIÈS <address@hidden>, + http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00095.html + Reference: http:// + ibm.biz/knowctr#ssw_aix_53/com.ibm.aix.basetechref/doc/basetrf1/getprocs.htm + */ + static char *p; + static int first = 1; + if (first) + { + first = 0; + pid_t pid = getpid (); + struct procentry64 procs; + p = (0 < getprocs64 (&procs, sizeof procs, NULL, 0, &pid, 1) + ? strdup (procs.pi_comm) + : NULL); + if (!p) + p = "?"; + } + return p; # else # error "getprogname module not ported to this OS" # endif