--- a/lib/getprogname.c Sat Dec 31 07:54:41 CST 2016 +++ b/lib/getprogname.c Thu Aug 22 17:48:57 CDT 2019 @@ -43,6 +43,14 @@ # include #endif +#ifdef __sgi +#include +#include +#include +#include +#include +#endif + #include "dirname.h" #ifndef HAVE_GETPROGNAME /* not Mac OS X, FreeBSD, NetBSD, OpenBSD >= 5.4, Cygwin */ @@ -143,6 +151,32 @@ free (buf.ps_pathptr); } return p; +# elif __sgi + char filename[50]; + int fd; + + sprintf (filename, "/proc/pinfo/%d", (int) getpid()); + fd = open(filename, O_RDONLY); + if (0 <= fd) + { + prpsinfo_t buf; + int ioctl_ok = 0 <= ioctl (fd, PIOCPSINFO, &buf); + close (fd); + if (ioctl_ok) + { + char *name = buf.pr_fname; + size_t namesize = sizeof buf.pr_fname; + char* namenul = memchr (name, '\0', namesize); + size_t namelen = namenul ? namenul - name : namesize; + char* namecopy = malloc(namelen+1); + if (namecopy) + { + namecopy[namelen] = 0; + return memcpy(namecopy, name, namelen); + } + } + } + return NULL; # else # error "getprogname module not ported to this OS" # endif