]> Savannah Git Hosting - gnulib.git/commitdiff
getprogname: new module
authorPino Toscano <ptoscano@redhat.com>
Thu, 18 Aug 2016 13:18:22 +0000 (15:18 +0200)
committerJim Meyering <meyering@fb.com>
Mon, 5 Sep 2016 16:21:54 +0000 (09:21 -0700)
This provides a LGPL module for getting the name of the current
program, using the same API found on *BSD systems.
* lib/getprogname.c, lib/getprogname.h, m4/getprogname.m4:
* modules/getprogname: New files.
* MODULES.html.sh (Misc): Add getprogname.
* NEWS: Document the deprecation of the 'progname' module.

ChangeLog
MODULES.html.sh
NEWS
lib/getprogname.c [new file with mode: 0644]
lib/getprogname.h [new file with mode: 0644]
m4/getprogname.m4 [new file with mode: 0644]
modules/getprogname [new file with mode: 0644]

index ba3e04817e3d66ccdb49a2d00b379ae45375abaf..dde0c725984c01837109c39e9a6d7bb4b8367b1a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2016-09-05  Pino Toscano  <ptoscano@redhat.com>
+
+       * NEWS: Document the deprecation of the 'progname' module.
+
+2016-08-18  Pino Toscano  <ptoscano@redhat.com>
+
+       getprogname: new module
+       This provides a LGPL module for getting the name of the current
+       program, using the same API found on *BSD systems.
+       * lib/getprogname.c, lib/getprogname.h, m4/getprogname.m4:
+       * modules/getprogname: New files.
+       * MODULES.html.sh (Misc): Add getprogname.
+
 2016-09-02  Jim Meyering  <meyering@fb.com>
 
        manywarnings: add -fno-common
index f1248386cbe6b734dc74c185f95c16e3873b4a86..ec6f30055342714980a93fd1e55168f71f2b45c5 100755 (executable)
@@ -3453,6 +3453,7 @@ func_all_modules ()
   func_module xgetdomainname
   func_module getloadavg
   func_module getpagesize
+  func_module getprogname
   func_module getusershell
   func_module lib-symbol-visibility
   func_module login_tty
diff --git a/NEWS b/NEWS
index e33d350146b9ab3a5e9155421c33b91f25506dad..ac302b59ae3c994dc8372bc5297ab971fdd8c748 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -42,6 +42,14 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2016-09-05  progname        This module is deprecated.  Please switch to the
+                            'getprogname' module and its getprogname()
+                            function to obtain the name of the current program.
+                            Note that there is no longer any need to export a
+                            'const char *program_name' variable.
+                            Currently there is no replacement for
+                            set_program_name().
+
 2016-08-17  stdbool         This no longer supports _Bool for C++.
                             Programs intended to be portable to C++
                             compilers should use plain 'bool' instead.
diff --git a/lib/getprogname.c b/lib/getprogname.c
new file mode 100644 (file)
index 0000000..ab26283
--- /dev/null
@@ -0,0 +1,45 @@
+/* Program name management.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "getprogname.h"
+
+#include <errno.h> /* get program_invocation_name declaration */
+#include <string.h>
+
+
+#ifndef HAVE_GETPROGNAME
+const char *
+getprogname (void)
+{
+#if HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
+  return program_invocation_short_name;
+#elif HAVE_DECL_PROGRAM_INVOCATION_NAME
+  const char *base = program_invocation_name;
+  const char *slash;
+
+  slash = strrchr (base, '/');
+  if (slash != NULL)
+    base = slash + 1;
+
+  return base;
+#else
+ #error "getprogname module not ported to this OS"
+#endif
+}
+#endif
diff --git a/lib/getprogname.h b/lib/getprogname.h
new file mode 100644 (file)
index 0000000..b21e423
--- /dev/null
@@ -0,0 +1,34 @@
+/* Program name management.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef _GL_GETPROGNAME_H
+#define _GL_GETPROGNAME_H
+
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef HAVE_GETPROGNAME
+extern const char *getprogname (void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/m4/getprogname.m4 b/m4/getprogname.m4
new file mode 100644 (file)
index 0000000..3d30550
--- /dev/null
@@ -0,0 +1,13 @@
+# getprogname.m4 - check for getprogname or replacements for it
+
+# Copyright (C) 2016 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# serial 1
+
+AC_DEFUN([gl_FUNC_GETPROGNAME],
+[
+  AC_CHECK_FUNCS_ONCE([getprogname])
+])
diff --git a/modules/getprogname b/modules/getprogname
new file mode 100644 (file)
index 0000000..efda4fa
--- /dev/null
@@ -0,0 +1,28 @@
+Description:
+Program name management.
+
+Files:
+lib/getprogname.h
+lib/getprogname.c
+m4/getprogname.m4
+
+Depends-on:
+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>])
+
+Makefile.am:
+lib_SOURCES += getprogname.h getprogname.c
+
+Include:
+"getprogname.h"
+
+License:
+LGPL
+
+Maintainer:
+All