diff options
| author | Jörg Frings-Fürst <debian@jff.email> | 2026-03-10 13:24:07 +0100 |
|---|---|---|
| committer | Jörg Frings-Fürst <debian@jff.email> | 2026-03-10 13:24:07 +0100 |
| commit | cfd1f17f1a85d95ea12bca8dae42add7dad1ad11 (patch) | |
| tree | 8016486f8ee7157213f2d09ff2491bfa9c94638a /tests/getprogname.c | |
| parent | 14e4d584d0121031ec40e6c35869745f1747ff29 (diff) | |
| parent | 1403307d6e2fb4e7b5d97a35f40d1e95134561ab (diff) | |
Merge branch 'release/debian/1.4.2-1'HEADdebian/1.4.2-1master
Diffstat (limited to 'tests/getprogname.c')
| -rw-r--r-- | tests/getprogname.c | 66 |
1 files changed, 10 insertions, 56 deletions
diff --git a/tests/getprogname.c b/tests/getprogname.c index 392a9a2f..8eec96c5 100644 --- a/tests/getprogname.c +++ b/tests/getprogname.c @@ -1,5 +1,5 @@ /* Program name management. - Copyright (C) 2016-2024 Free Software Foundation, Inc. + Copyright (C) 2016-2026 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -42,14 +42,6 @@ # include <string.h> #endif -#if defined __sgi || defined __osf__ -# include <string.h> -# include <unistd.h> -# include <stdio.h> -# include <fcntl.h> -# include <sys/procfs.h> -#endif - #if defined __SCO_VERSION__ || defined __sysv5__ # include <fcntl.h> # include <string.h> @@ -137,7 +129,7 @@ getprogname (void) else p = cmd; if (strlen (p) > PST_UCOMMLEN - 1 - && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0) + && memeq (p, ucomm, PST_UCOMMLEN - 1)) /* p is less truncated than ucomm. */ ; else @@ -173,7 +165,7 @@ getprogname (void) else p = cmd; if (strlen (p) > PST_UCOMMLEN - 1 - && memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0) + && memeq (p, ucomm, PST_UCOMMLEN - 1)) /* p is less truncated than ucomm. */ ; else @@ -196,7 +188,6 @@ getprogname (void) if (first) { pid_t pid = getpid (); - int token; W_PSPROC buf; first = 0; memset (&buf, 0, sizeof(buf)); @@ -205,7 +196,8 @@ getprogname (void) buf.ps_pathptr = (char *) malloc (buf.ps_pathlen = PS_PATHBLEN); if (buf.ps_cmdptr && buf.ps_conttyptr && buf.ps_pathptr) { - for (token = 0; token >= 0; + for (int token = 0; + token >= 0; token = w_getpsent (token, &buf, sizeof(buf))) { if (token > 0 && buf.ps_pid == pid) @@ -234,60 +226,22 @@ getprogname (void) free (buf.ps_pathptr); } return p; -# elif defined __sgi || defined __osf__ /* IRIX or Tru64 */ - char filename[50]; - int fd; - - # if defined __sgi - sprintf (filename, "/proc/pinfo/%d", (int) getpid ()); - # else - sprintf (filename, "/proc/%d", (int) getpid ()); - # endif - fd = open (filename, O_RDONLY | O_CLOEXEC); - 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; - /* It may not be NUL-terminated. */ - 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; # 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); + int 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, '/'); + char *progname = strrchr (buf, '/'); if (progname) - { - progname = progname + 1; /* Skip the '/' */ - } + progname = progname + 1; /* Skip the '/' */ else - { - progname = buf; - } - char *ret; - ret = malloc (strlen (progname) + 1); + progname = buf; + char *ret = malloc (strlen (progname) + 1); if (ret) { strcpy (ret, progname); |
