From e24a470105e085d18f08227fe0b1c49ef86c5814 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 21 Sep 2016 21:15:59 -0700 Subject: [PATCH] getprogname: port to AIX MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * 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. --- ChangeLog | 10 ++++++++++ lib/getprogname.c | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/ChangeLog b/ChangeLog index 82f4264d34..417de6ab77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2016-09-21 Jim Meyering + + 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 extensions: fix typo in comment diff --git a/lib/getprogname.c b/lib/getprogname.c index d70c2aa20d..17e6059e1c 100644 --- a/lib/getprogname.c +++ b/lib/getprogname.c @@ -22,6 +22,12 @@ #include /* get program_invocation_name declaration */ #include /* get __argv declaration */ +#ifdef _AIX +# include +# include +# include +#endif + #include "dirname.h" #ifndef HAVE_GETPROGNAME @@ -41,6 +47,26 @@ getprogname (void) # elif HAVE_DECL___ARGV const char *p = __argv && __argv[0] ? __argv[0] : "?"; return last_component (p); +# elif _AIX + /* Idea by Bastien ROUCARIÈS , + 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 -- 2.39.5