bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Port getprogname module to SCO OpenServer


From: Benji Wiebe
Subject: Port getprogname module to SCO OpenServer
Date: Wed, 30 Sep 2020 22:30:14 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0

I ported the getprogname module to SCO OpenServer 6 (should also work on OSR5 and UnixWare). It prevents several OSS packages from building.

I just made it read from /proc/<pid>/cmdline to get the command name. The patch is below. Comments are welcome. Thanks!

-Benji



diff --git a/lib/getprogname.c b/lib/getprogname.c
index 744466ea9..9ee4c226d 100644
--- a/lib/getprogname.c
+++ b/lib/getprogname.c
@@ -51,6 +51,11 @@
 # include <sys/procfs.h>
 #endif

+#ifdef __SCO_VERSION__
+# include <fcntl.h>
+# include <stdlib.h>
+#endif
+
 #include "basename-lgpl.h"

 #ifndef HAVE_GETPROGNAME             /* not Mac OS X, FreeBSD, NetBSD, OpenBSD >= 5.4, Cygwin */
@@ -245,6 +250,39 @@ getprogname (void)
         }
     }
   return NULL;
+# elif defined __SCO_VERSION__                              /* SCO OpenServer/UnixWare */
+  char buf[50];
+  char *ret;
+  int fd;
+  int pathlen;
+  sprintf (buf, "/proc/%d/cmdline", (int)getpid());
+  fd = open (buf, O_RDONLY);
+  if (0 <= fd)
+    {
+      size_t n = read (fd, buf, 49);
+      if (n > 0)
+        {
+          buf[49] = '\0'; /* Guarantee null-termination */
+          pathlen = strlen (buf);
+          ret = malloc (pathlen + 1);
+          if (ret)
+            {
+              int i;
+              int pathsep = 0;
+              for (i = 0; i < pathlen; i++)
+                {
+                  if (buf[i] == '/')
+                    {
+                      pathsep = i;
+                    }
+                }
+              strcpy (ret, buf + pathsep + 1);
+              return ret;
+          }
+        }
+      close (fd);
+    }
+  return "?";
 # else
 #  error "getprogname module not ported to this OS"
 # endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]