diff options
author | Clint Adams <clint@debian.org> | 2017-02-04 10:14:44 -0500 |
---|---|---|
committer | Clint Adams <clint@debian.org> | 2017-02-04 10:14:44 -0500 |
commit | 1c0d840cad3dc7c951a86c9c128a721e9ebcd2cf (patch) | |
tree | 5e324772945801fb9028da20aa870dc27ca77597 /lib/getprogname.c | |
parent | 29d3f78df4630dbee0a141e2be8e77275724b3a8 (diff) |
New upstream version 4.4
Diffstat (limited to 'lib/getprogname.c')
-rw-r--r-- | lib/getprogname.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/getprogname.c b/lib/getprogname.c index a7246e9..5295484 100644 --- a/lib/getprogname.c +++ b/lib/getprogname.c @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2016 Free Software Foundation, Inc. + Copyright (C) 2016-2017 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 @@ -43,6 +43,14 @@ # include <string.h> #endif +#ifdef __sgi +# include <string.h> +# include <unistd.h> +# include <stdio.h> +# include <fcntl.h> +# include <sys/procfs.h> +#endif + #include "dirname.h" #ifndef HAVE_GETPROGNAME /* not Mac OS X, FreeBSD, NetBSD, OpenBSD >= 5.4, Cygwin */ @@ -143,6 +151,32 @@ getprogname (void) free (buf.ps_pathptr); } return p; +# elif defined __sgi /* IRIX */ + 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; + char *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 |