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 #endif +#if defined __SCO_VERSION__ || defined __sysv5__ +# include +# include +# include +#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