* lib/getprogname.c (__progname) [HAVE_DECL___PROGNAME]: Declare.
(getprogname) [HAVE_DECL___PROGNAME]: Return __progname or "?".
* modules/getprogname (configure.ac): Move most of this code...
* m4/getprogname.m4 (gl_FUNC_GETPROGNAME): ... to this function,
increment serial number, and add a test for __progname.
https://bugs.gnu.org/24562
Reported by Nelson H. F. Beebe.
+2016-09-28 Jim Meyering <meyering@fb.com>
+
+ getprogname: port to OpenBSD 5.1
+ * lib/getprogname.c (__progname) [HAVE_DECL___PROGNAME]: Declare.
+ (getprogname) [HAVE_DECL___PROGNAME]: Return __progname or "?".
+ * modules/getprogname (configure.ac): Move most of this code...
+ * m4/getprogname.m4 (gl_FUNC_GETPROGNAME): ... to this function,
+ increment serial number, and add a test for __progname.
+ https://bugs.gnu.org/24562
+ Reported by Nelson H. F. Beebe.
+
2016-09-24 Paul Eggert <eggert@cs.ucla.edu>
sched: port to GCC 6.2.1 on macOS Sierra
#ifndef HAVE_GETPROGNAME
+# ifdef HAVE_DECL___PROGNAME
+char *__progname;
+# endif
+
char const *
getprogname (void)
{
# elif HAVE_DECL___ARGV
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]. */
+ const char *p = __progname;
+ return p && p[0] ? p : "?";
# elif _AIX
/* Idea by Bastien ROUCARIÈS <address@hidden>,
http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00095.html
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
-# serial 2
+# serial 3
AC_DEFUN([gl_FUNC_GETPROGNAME],
[
AC_CHECK_FUNCS_ONCE([getprogname getexecname])
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+ AC_CHECK_DECLS([program_invocation_name], [], [], [#include <errno.h>])
+ AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include <errno.h>])
+ AC_CHECK_DECLS([__argv], [], [], [#include <stdlib.h>])
+ AC_CHECK_DECLS([__progname], [], [], [char *__progname;])
])
configure.ac:
gl_FUNC_GETPROGNAME
-AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
-AC_CHECK_DECLS([program_invocation_name], [], [], [#include <errno.h>])
-AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include <errno.h>])
-AC_CHECK_DECLS([__argv], [], [], [#include <stdlib.h>])
Makefile.am:
lib_SOURCES += getprogname.h getprogname.c