summaryrefslogtreecommitdiff
path: root/tests/getprogname.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/getprogname.c')
-rw-r--r--tests/getprogname.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/tests/getprogname.c b/tests/getprogname.c
index 4da2159f..8eec96c5 100644
--- a/tests/getprogname.c
+++ b/tests/getprogname.c
@@ -1,5 +1,5 @@
/* Program name management.
- Copyright (C) 2016-2025 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
@@ -188,7 +188,6 @@ getprogname (void)
if (first)
{
pid_t pid = getpid ();
- int token;
W_PSPROC buf;
first = 0;
memset (&buf, 0, sizeof(buf));
@@ -197,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)
@@ -228,27 +228,20 @@ getprogname (void)
return p;
# 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);