Mercurial > gnulib
comparison lib/getprogname.c @ 39903:cadbcf6826fd
getprogname: Work around program name truncation when possible.
* lib/getprogname.c (getprogname) [HP-UX]: When pst_ucomm is truncated,
possibly use pst_cmd instead.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Thu, 11 Oct 2018 18:24:51 +0200 |
parents | 33ee5e90be64 |
children | 7bdba2aa999b |
comparison
equal
deleted
inserted
replaced
39902:74aa8d21daa5 | 39903:cadbcf6826fd |
---|---|
108 if (first) | 108 if (first) |
109 { | 109 { |
110 first = 0; | 110 first = 0; |
111 pid_t pid = getpid (); | 111 pid_t pid = getpid (); |
112 struct pst_status status; | 112 struct pst_status status; |
113 p = (0 < pstat_getproc (&status, sizeof status, 0, pid) | 113 if (pstat_getproc (&status, sizeof status, 0, pid) > 0) |
114 ? strdup (status.pst_ucomm) | 114 { |
115 : NULL); | 115 if (strlen (status.pst_ucomm) < PST_UCOMMLEN - 1) |
116 p = status.pst_ucomm; | |
117 else | |
118 { | |
119 /* status.pst_ucomm is truncated to length PST_UCOMMLEN - 1. | |
120 Look at status.pst_cmd instead. */ | |
121 char *space = strchr (status.pst_cmd, ' '); | |
122 if (space != NULL) | |
123 *space = '\0'; | |
124 p = strrchr (status.pst_cmd, '/'); | |
125 if (p != NULL) | |
126 p++; | |
127 else | |
128 p = status.pst_cmd; | |
129 if (strlen (p) > PST_UCOMMLEN - 1 | |
130 && memcmp (p, status.pst_ucomm, PST_UCOMMLEN - 1) == 0) | |
131 /* p is less truncated than status.pst_ucomm. */ | |
132 ; | |
133 else | |
134 p = status.pst_ucomm; | |
135 } | |
136 p = strdup (p); | |
137 } | |
138 else | |
139 p = NULL; | |
116 if (!p) | 140 if (!p) |
117 p = "?"; | 141 p = "?"; |
118 } | 142 } |
119 return p; | 143 return p; |
120 # elif __MVS__ /* z/OS */ | 144 # elif __MVS__ /* z/OS */ |