getprogname: port to OpenBSD 5.1
authorJim Meyering <meyering@fb.com>
Wed, 28 Sep 2016 18:09:03 +0000 (11:09 -0700)
committerJim Meyering <meyering@fb.com>
Wed, 28 Sep 2016 18:52:37 +0000 (11:52 -0700)
* 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.

ChangeLog
lib/getprogname.c
m4/getprogname.m4
modules/getprogname

index d929818f4147d6b0b688ed65338875ca5f1608ec..121c0c319a7abad48085780f3e0b477f6248025a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+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
index 17e6059e1c1360d5cf131bcb04ac20d6f79c0960..1e2ba20a53531a671140cf56947e500877951742 100644 (file)
 
 #ifndef HAVE_GETPROGNAME
 
+# ifdef HAVE_DECL___PROGNAME
+char *__progname;
+# endif
+
 char const *
 getprogname (void)
 {
@@ -47,6 +51,11 @@ 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
index 52f022489d167b056aac6f8a04572ec5b3277f9f..ec3ac8fb21e954f843c35e084a6d0f41e1c310a1 100644 (file)
@@ -5,9 +5,14 @@
 # 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;])
 ])
index 1a263984082d779268dcfdddece49a52cc63d210..0b3d8fca84a6b6856dab312362759a891f27a172 100644 (file)
@@ -12,10 +12,6 @@ extensions
 
 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