]> Savannah Git Hosting - gnulib.git/commitdiff
getprogname: avoid __progname vs program_invocation_short_name pitfall
authorJim Meyering <meyering@fb.com>
Thu, 29 Sep 2016 03:57:24 +0000 (20:57 -0700)
committerJim Meyering <meyering@fb.com>
Thu, 29 Sep 2016 04:07:26 +0000 (21:07 -0700)
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".

ChangeLog
lib/getprogname.c

index 121c0c319a7abad48085780f3e0b477f6248025a..21a55e82aa9d236fb8ccc00197a4b1aa91136dd4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2016-09-28  Jim Meyering  <meyering@fb.com>
 
+       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 "?".
index 1e2ba20a53531a671140cf56947e500877951742..7de231768f946ddedd4ea393fa5cb8fee54e617c 100644 (file)
 
 #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