diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-12-02 10:30:25 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-12-02 10:30:25 +0100 |
commit | 44a3eaeba04ef78835ca741592c376428ada5f71 (patch) | |
tree | 29cc935fd475678dcbe38972bfa77fdc68ffb10d /tests/getprogname.c | |
parent | 6b73edd95d603e27d55d4905134ac1327d426534 (diff) |
New upstream version 0.9.8upstream/0.9.8
Diffstat (limited to 'tests/getprogname.c')
-rw-r--r-- | tests/getprogname.c | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/tests/getprogname.c b/tests/getprogname.c index a7246e9..a2b2336 100644 --- a/tests/getprogname.c +++ b/tests/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 @@ -12,7 +12,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. */ + along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <config.h> @@ -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 */ @@ -56,7 +64,7 @@ getprogname (void) /* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */ return last_component (program_invocation_name); # elif HAVE_GETEXECNAME /* Solaris */ - /* http://docs.oracle.com/cd/E19253-01/816-5168/6mbb3hrb1/index.html */ + /* https://docs.oracle.com/cd/E19253-01/816-5168/6mbb3hrb1/index.html */ const char *p = getexecname (); if (!p) p = "?"; @@ -66,7 +74,7 @@ getprogname (void) const char *p = __argv && __argv[0] ? __argv[0] : "?"; return last_component (p); # elif HAVE_VAR___PROGNAME /* OpenBSD, QNX */ - /* http://man.openbsd.org/style.9 */ + /* https://man.openbsd.org/style.9 */ /* http://www.qnx.de/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neutrino_lib_ref%2Fp%2F__progname.html */ /* Be careful to declare this only when we absolutely need it (OpenBSD 5.1), rather than when it's available. Otherwise, @@ -77,9 +85,8 @@ getprogname (void) return p && p[0] ? p : "?"; # elif _AIX /* AIX */ /* Idea by Bastien ROUCARIÈS, - http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00095.html - Reference: http:// - ibm.biz/knowctr#ssw_aix_53/com.ibm.aix.basetechref/doc/basetrf1/getprocs.htm + https://lists.gnu.org/r/bug-gnulib/2010-12/msg00095.html + Reference: https://www.ibm.com/support/knowledgecenter/en/ssw_aix_61/com.ibm.aix.basetrf1/getprocs.htm */ static char *p; static int first = 1; @@ -143,6 +150,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; + 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 |