From: Daniel Richard G Date: Thu, 13 Oct 2016 08:42:42 +0000 (+0100) Subject: getprogname: port to IBM z/OS X-Git-Tag: v1.0~6610 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=d75cbb37083ed4155ad8d485ae5de6c58d62f981;p=gnulib.git getprogname: port to IBM z/OS * lib/getprogname.c (getprogname): Use w_getpsent() to get the name. --- diff --git a/ChangeLog b/ChangeLog index 6cf41421c6..070e498d55 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2016-10-13 Daniel Richard G. + + getprogname: port to IBM z/OS + * lib/getprogname.c (getprogname): Use w_getpsent() to get the name. + 2016-10-11 Jim Meyering maint: remove stray space after "." in AC_DEFINE comment. diff --git a/lib/getprogname.c b/lib/getprogname.c index 97a6aef943..a19612ab37 100644 --- a/lib/getprogname.c +++ b/lib/getprogname.c @@ -28,6 +28,14 @@ # include #endif +#ifdef __MVS__ +# ifndef _OPEN_SYS +# define _OPEN_SYS +# endif +# include +# include +#endif + #include "dirname.h" #ifndef HAVE_GETPROGNAME @@ -75,6 +83,37 @@ getprogname (void) p = "?"; } return p; +#elif __MVS__ + /* https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.bpxbd00/rtwgetp.htm */ + static char *p = "?"; + static int first = 1; + if (first) + { + pid_t pid = getpid (); + int token; + W_PSPROC buf; + first = 0; + memset (&buf, 0, sizeof(buf)); + buf.ps_cmdptr = (char *) malloc (buf.ps_cmdlen = PS_CMDBLEN_LONG); + buf.ps_conttyptr = (char *) malloc (buf.ps_conttylen = PS_CONTTYBLEN); + buf.ps_pathptr = (char *) malloc (buf.ps_pathlen = PS_PATHBLEN); + if (buf.ps_cmdptr && buf.ps_conttyptr && buf.ps_pathptr) + { + for (token = 0; token >= 0; + token = w_getpsent (token, &buf, sizeof(buf))) + { + if (token > 0 && buf.ps_pid == pid) + { + p = strdup (last_component (buf.ps_pathptr)); + break; + } + } + } + free (buf.ps_cmdptr); + free (buf.ps_conttyptr); + free (buf.ps_pathptr); + } + return p; # else # error "getprogname module not ported to this OS" # endif