]> Savannah Git Hosting - gnulib.git/commitdiff
getprogname: port to IBM z/OS
authorDaniel Richard G <skunk@iSKUNK.ORG>
Thu, 13 Oct 2016 08:42:42 +0000 (09:42 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 13 Oct 2016 08:48:12 +0000 (09:48 +0100)
* lib/getprogname.c (getprogname): Use w_getpsent() to get the name.

ChangeLog
lib/getprogname.c

index 6cf41421c607601a086f1352589a0ad82afe799c..070e498d55466cf511305e7c4b207d5cc628e06d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-10-13  Daniel Richard G.  <skunk@iSKUNK.ORG>
+
+       getprogname: port to IBM z/OS
+       * lib/getprogname.c (getprogname): Use w_getpsent() to get the name.
+
 2016-10-11  Jim Meyering  <meyering@fb.com>
 
        maint: remove stray space after "." in AC_DEFINE comment.
index 97a6aef943ef1617e687d889635236b0b4961c15..a19612ab37afe0675439b33377acdc67221b2020 100644 (file)
 # include <string.h>
 #endif
 
+#ifdef __MVS__
+# ifndef _OPEN_SYS
+#  define _OPEN_SYS
+# endif
+# include <string.h>
+# include <sys/ps.h>
+#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