FYI: grep (due to its use of the new getprogname module) would fail to
configure on OpenBSD 5.1. I'll soon push this to gnulib and then
update grep's gnulib submodule to latest to pull it in.
From d02282b67dcc6d42be8ab89e5ae2122dd01be7b4 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyer...@fb.com>
Date: Wed, 28 Sep 2016 11:09:03 -0700
Subject: [PATCH] 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.
Reported by Nelson H. F. Beebe.
---
 ChangeLog           | 10 ++++++++++
 lib/getprogname.c   |  9 +++++++++
 m4/getprogname.m4   |  7 ++++++-
 modules/getprogname |  4 ----
 4 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b006ef0..f258ac4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2016-09-28  Jim Meyering  <meyer...@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.
+       Reported by Nelson H. F. Beebe.
+
 2016-09-24  Paul Eggert  <egg...@cs.ucla.edu>

        tests/init.sh: port Alpine fix to AIX 7.1
diff --git a/lib/getprogname.c b/lib/getprogname.c
index 17e6059..1e2ba20 100644
--- a/lib/getprogname.c
+++ b/lib/getprogname.c
@@ -32,6 +32,10 @@

 #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
diff --git a/m4/getprogname.m4 b/m4/getprogname.m4
index 52f0224..ec3ac8f 100644
--- a/m4/getprogname.m4
+++ b/m4/getprogname.m4
@@ -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;])
 ])
diff --git a/modules/getprogname b/modules/getprogname
index 1a26398..0b3d8fc 100644
--- a/modules/getprogname
+++ b/modules/getprogname
@@ -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
-- 
2.7.4

Reply via email to