"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/getprogname.c" between
le-1.16.5.tar.gz and le-1.16.6.tar.gz

About: le is a terminal text editor (many block operations with stream and rectangular blocks, tunable syntax highlighting, etc.).

getprogname.c  (le-1.16.5):getprogname.c  (le-1.16.6)
/* Program name management. /* Program name management.
Copyright (C) 2016-2017 Free Software Foundation, Inc. Copyright (C) 2016-2019 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or the Free Software Foundation; either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License 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> #include <config.h>
/* Specification. */ /* Specification. */
#include "getprogname.h" #include "getprogname.h"
#include <errno.h> /* get program_invocation_name declaration */ #include <errno.h> /* get program_invocation_name declaration */
#include <stdlib.h> /* get __argv declaration */ #include <stdlib.h> /* get __argv declaration */
#ifdef _AIX #ifdef _AIX
skipping to change at line 67 skipping to change at line 67
char const * char const *
getprogname (void) getprogname (void)
{ {
# if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME /* glibc, BeOS */ # if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME /* glibc, BeOS */
/* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */ /* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */
return program_invocation_short_name; return program_invocation_short_name;
# elif HAVE_DECL_PROGRAM_INVOCATION_NAME /* glibc, BeOS */ # elif HAVE_DECL_PROGRAM_INVOCATION_NAME /* glibc, BeOS */
/* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */ /* https://www.gnu.org/software/libc/manual/html_node/Error-Messages.html */
return last_component (program_invocation_name); return last_component (program_invocation_name);
# elif HAVE_GETEXECNAME /* Solaris */ # 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 (); const char *p = getexecname ();
if (!p) if (!p)
p = "?"; p = "?";
return last_component (p); return last_component (p);
# elif HAVE_DECL___ARGV /* mingw, MSVC */ # elif HAVE_DECL___ARGV /* mingw, MSVC */
/* https://msdn.microsoft.com/en-us/library/dn727674.aspx */ /* https://msdn.microsoft.com/en-us/library/dn727674.aspx */
const char *p = __argv && __argv[0] ? __argv[0] : "?"; const char *p = __argv && __argv[0] ? __argv[0] : "?";
return last_component (p); return last_component (p);
# elif HAVE_VAR___PROGNAME /* OpenBSD, QNX */ # elif HAVE_VAR___PROGNAME /* OpenBSD, Android,
/* http://man.openbsd.org/style.9 */ QNX */
/* https://man.openbsd.org/style.9 */
/* http://www.qnx.de/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neut rino_lib_ref%2Fp%2F__progname.html */ /* http://www.qnx.de/developers/docs/6.5.0/index.jsp?topic=%2Fcom.qnx.doc.neut rino_lib_ref%2Fp%2F__progname.html */
/* Be careful to declare this only when we absolutely need it /* Be careful to declare this only when we absolutely need it
(OpenBSD 5.1), rather than when it's available. Otherwise, (OpenBSD 5.1), rather than when it's available. Otherwise,
its mere declaration makes program_invocation_short_name its mere declaration makes program_invocation_short_name
malfunction (have zero length) with Fedora 25's glibc. */ malfunction (have zero length) with Fedora 25's glibc. */
extern char *__progname; extern char *__progname;
const char *p = __progname; const char *p = __progname;
# if defined __ANDROID__
return last_component (p);
# else
return p && p[0] ? p : "?"; return p && p[0] ? p : "?";
# endif
# elif _AIX /* AIX */ # elif _AIX /* AIX */
/* Idea by Bastien ROUCARIÈS, /* Idea by Bastien ROUCARIÈS,
http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00095.html https://lists.gnu.org/r/bug-gnulib/2010-12/msg00095.html
Reference: http:// Reference: https://www.ibm.com/support/knowledgecenter/en/ssw_aix_61/com.ib
ibm.biz/knowctr#ssw_aix_53/com.ibm.aix.basetechref/doc/basetrf1/getprocs.htm m.aix.basetrf1/getprocs.htm
*/ */
static char *p; static char *p;
static int first = 1; static int first = 1;
if (first) if (first)
{ {
first = 0; first = 0;
pid_t pid = getpid (); pid_t pid = getpid ();
struct procentry64 procs; struct procentry64 procs;
p = (0 < getprocs64 (&procs, sizeof procs, NULL, 0, &pid, 1) p = (0 < getprocs64 (&procs, sizeof procs, NULL, 0, &pid, 1)
? strdup (procs.pi_comm) ? strdup (procs.pi_comm)
skipping to change at line 114 skipping to change at line 117
} }
return p; return p;
# elif defined __hpux # elif defined __hpux
static char *p; static char *p;
static int first = 1; static int first = 1;
if (first) if (first)
{ {
first = 0; first = 0;
pid_t pid = getpid (); pid_t pid = getpid ();
struct pst_status status; struct pst_status status;
p = (0 < pstat_getproc (&status, sizeof status, 0, pid) if (pstat_getproc (&status, sizeof status, 0, pid) > 0)
? strdup (status.pst_ucomm) {
: NULL); char *ucomm = status.pst_ucomm;
char *cmd = status.pst_cmd;
if (strlen (ucomm) < PST_UCOMMLEN - 1)
p = ucomm;
else
{
/* ucomm is truncated to length PST_UCOMMLEN - 1.
Look at cmd instead. */
char *space = strchr (cmd, ' ');
if (space != NULL)
*space = '\0';
p = strrchr (cmd, '/');
if (p != NULL)
p++;
else
p = cmd;
if (strlen (p) > PST_UCOMMLEN - 1
&& memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
/* p is less truncated than ucomm. */
;
else
p = ucomm;
}
p = strdup (p);
}
else
{
# if !defined __LP64__
/* Support for 32-bit programs running in 64-bit HP-UX.
The documented way to do this is to use the same source code
as above, but in a compilation unit where '#define _PSTAT64 1'
is in effect. I prefer a single compilation unit; the struct
size and the offsets are not going to change. */
char status64[1216];
if (__pstat_getproc64 (status64, sizeof status64, 0, pid) > 0)
{
char *ucomm = status64 + 288;
char *cmd = status64 + 168;
if (strlen (ucomm) < PST_UCOMMLEN - 1)
p = ucomm;
else
{
/* ucomm is truncated to length PST_UCOMMLEN - 1.
Look at cmd instead. */
char *space = strchr (cmd, ' ');
if (space != NULL)
*space = '\0';
p = strrchr (cmd, '/');
if (p != NULL)
p++;
else
p = cmd;
if (strlen (p) > PST_UCOMMLEN - 1
&& memcmp (p, ucomm, PST_UCOMMLEN - 1) == 0)
/* p is less truncated than ucomm. */
;
else
p = ucomm;
}
p = strdup (p);
}
else
# endif
p = NULL;
}
if (!p) if (!p)
p = "?"; p = "?";
} }
return p; return p;
# elif __MVS__ /* z/OS */ # elif __MVS__ /* z/OS */
/* https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.b pxbd00/rtwgetp.htm */ /* https://www.ibm.com/support/knowledgecenter/SSLTBW_2.1.0/com.ibm.zos.v2r1.b pxbd00/rtwgetp.htm */
static char *p = "?"; static char *p = "?";
static int first = 1; static int first = 1;
if (first) if (first)
{ {
skipping to change at line 168 skipping to change at line 235
sprintf (filename, "/proc/pinfo/%d", (int) getpid ()); sprintf (filename, "/proc/pinfo/%d", (int) getpid ());
fd = open (filename, O_RDONLY); fd = open (filename, O_RDONLY);
if (0 <= fd) if (0 <= fd)
{ {
prpsinfo_t buf; prpsinfo_t buf;
int ioctl_ok = 0 <= ioctl (fd, PIOCPSINFO, &buf); int ioctl_ok = 0 <= ioctl (fd, PIOCPSINFO, &buf);
close (fd); close (fd);
if (ioctl_ok) if (ioctl_ok)
{ {
char *name = buf.pr_fname; char *name = buf.pr_fname;
char *namesize = sizeof buf.pr_fname; size_t namesize = sizeof buf.pr_fname;
char *namenul = memchr (name, '\0', namesize); char *namenul = memchr (name, '\0', namesize);
size_t namelen = namenul ? namenul - name : namesize; size_t namelen = namenul ? namenul - name : namesize;
char *namecopy = malloc (namelen + 1); char *namecopy = malloc (namelen + 1);
if (namecopy) if (namecopy)
{ {
namecopy[namelen] = 0; namecopy[namelen] = 0;
return memcpy (namecopy, name, namelen); return memcpy (namecopy, name, namelen);
} }
} }
} }
return NULL; return NULL;
# else # else
# error "getprogname module not ported to this OS" # error "getprogname module not ported to this OS"
# endif # endif
} }
#endif #endif
/*
* Hey Emacs!
* Local Variables:
* coding: utf-8
* End:
*/
 End of changes. 10 change blocks. 
12 lines changed or deleted 81 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)