It is better, but there are still (minor) things to tweak.
Minor things tweaked.

I'm not sure why I cast getpid to int.

Including string.h did fix the strrchr warning.

Now using __SCO_SERVER__ || __sysv5__ for OpenServer6/UnixWare7 and SCO cc/GCC detection.

Also as far as the indentation goes, it is correct as far as I can tell. It does look weird; I just copied the style from the IRIX implementation just above this one in the getprogname.c file.

Attached is the new patch.

diff --git a/lib/getprogname.c b/lib/getprogname.c
index 744466ea9..4133e1391 100644
--- a/lib/getprogname.c
+++ b/lib/getprogname.c
@@ -51,6 +51,12 @@
 # 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

Reply via email to