]> Savannah Git Hosting - gnulib.git/commitdiff
getprogname: Add support for OpenServer 6 and UnixWare 7.
authorBenji Wiebe <benjiwiebe14@gmail.com>
Sun, 11 Oct 2020 19:14:43 +0000 (21:14 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 11 Oct 2020 19:14:43 +0000 (21:14 +0200)
* lib/getprogname.c: Include <fcntl.h>, <stdlib.h>, <string.h>.
(getprogname): On OpenServer6 and UnixWare, read /proc/<pid>/cmdline.

ChangeLog
lib/getprogname.c

index 14dc601caa06f54de9fdcea714bfa395724197bf..6a0e15de72da51da6fb1c56552538dfd6fa884a3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2020-10-11  Benji Wiebe  <benjiwiebe14@gmail.com>
+
+       getprogname: Add support for OpenServer 6 and UnixWare 7.
+       * lib/getprogname.c: Include <fcntl.h>, <stdlib.h>, <string.h>.
+       (getprogname): On OpenServer6 and UnixWare, read /proc/<pid>/cmdline.
+
 2020-10-11  Bruno Haible  <bruno@clisp.org>
 
        tests: Avoid a name clash on UnixWare.
index 744466ea920653cbc51b66606ef6fcded447485f..23b17438c6e8ddd17a05be7ee46cf688b7a62c84 100644 (file)
 # include <sys/procfs.h>
 #endif
 
+#if defined __SCO_VERSION__ || defined __sysv5__
+# include <fcntl.h>
+# include <stdlib.h>
+# include <string.h>
+#endif
+
 #include "basename-lgpl.h"
 
 #ifndef HAVE_GETPROGNAME             /* not Mac OS X, FreeBSD, NetBSD, OpenBSD >= 5.4, Cygwin */
@@ -245,6 +251,38 @@ getprogname (void)
         }
     }
   return NULL;
+# elif defined __SCO_VERSION__ || defined __sysv5__                /* SCO OpenServer6/UnixWare */
+  char buf[80];
+  int fd;
+  sprintf (buf, "/proc/%d/cmdline", getpid());
+  fd = open (buf, O_RDONLY);
+  if (0 <= fd)
+    {
+      size_t n = read (fd, buf, 79);
+      if (n > 0)
+        {
+          buf[n] = '\0'; /* Guarantee null-termination */
+          char *progname;
+          progname = strrchr (buf, '/');
+          if (progname)
+            {
+              progname = progname + 1; /* Skip the '/' */
+            }
+          else
+            {
+              progname = buf;
+            }
+          char *ret;
+          ret = malloc (strlen (progname) + 1);
+          if (ret)
+            {
+              strcpy (ret, progname);
+              return ret;
+            }
+        }
+      close (fd);
+    }
+  return "?";
 # else
 #  error "getprogname module not ported to this OS"
 # endif