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 "?".
#ifndef HAVE_GETPROGNAME
-# ifdef HAVE_DECL___PROGNAME
-char *__progname;
-# endif
-
char const *
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