From: Jim Meyering Date: Thu, 29 Sep 2016 03:57:24 +0000 (-0700) Subject: getprogname: avoid __progname vs program_invocation_short_name pitfall X-Git-Tag: v1.0~6624 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=af62896a5bd7c63b9569813a0eff11b6b4ab665d;p=gnulib.git getprogname: avoid __progname vs program_invocation_short_name pitfall I.e., don't let the OpenBSD 5.1 fix induce failure when using newer glibc. Would have caused failure with Fedora 25's glibc-2.24-3, but not with Fedora 24's glibc-2.23.1-10. * lib/getprogname.c (__progname): Move this declaration down... (getprogname): ... into the #elif block where used, and make it explicitly "extern". --- diff --git a/ChangeLog b/ChangeLog index 121c0c319a..21a55e82aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2016-09-28 Jim Meyering + getprogname: avoid __progname vs program_invocation_short_name pitfall + I.e., don't let the OpenBSD 5.1 fix induce failure when using newer + glibc. Would have caused failure with Fedora 25's glibc-2.24-3, but + not with Fedora 24's glibc-2.23.1-10. + * lib/getprogname.c (__progname): Move this declaration down... + (getprogname): ... into the #elif block where used, and make it + explicitly "extern". + getprogname: port to OpenBSD 5.1 * lib/getprogname.c (__progname) [HAVE_DECL___PROGNAME]: Declare. (getprogname) [HAVE_DECL___PROGNAME]: Return __progname or "?". diff --git a/lib/getprogname.c b/lib/getprogname.c index 1e2ba20a53..7de231768f 100644 --- a/lib/getprogname.c +++ b/lib/getprogname.c @@ -32,10 +32,6 @@ #ifndef HAVE_GETPROGNAME -# ifdef HAVE_DECL___PROGNAME -char *__progname; -# endif - char const * getprogname (void) { @@ -52,8 +48,11 @@ getprogname (void) const char *p = __argv && __argv[0] ? __argv[0] : "?"; return last_component (p); # elif HAVE_DECL___PROGNAME - /* This variable exists at least on OpenBSD 5.1 and glibc-2.23, - and appears always to be the basename component of argv[0]. */ + /* Be careful to declare this only when we absolutely need it + (OpenBSD 5.1), rather than when it's available. Otherwise, + its mere declaration makes program_invocation_short_name + malfunction (have zero length) with Fedora 25's glibc. */ + extern char *__progname; const char *p = __progname; return p && p[0] ? p : "?"; # elif _AIX