diff options
Diffstat (limited to 'gnulib/import/getprogname.c')
-rw-r--r-- | gnulib/import/getprogname.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/gnulib/import/getprogname.c b/gnulib/import/getprogname.c index b9667ff..500619d 100644 --- a/gnulib/import/getprogname.c +++ b/gnulib/import/getprogname.c @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2016-2020 Free Software Foundation, Inc. + Copyright (C) 2016-2021 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,7 +51,13 @@ # include <sys/procfs.h> #endif -#include "dirname.h" +#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 */ char const * @@ -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 |