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.
---
ChangeLog | 8 ++++++++
lib/getprogname.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
lib/getprogname.h | 34 ++++++++++++++++++++++++++++++++++
m4/getprogname.m4 | 13 +++++++++++++
modules/getprogname | 28 ++++++++++++++++++++++++++++
5 files changed, 128 insertions(+)
create mode 100644 lib/getprogname.c
create mode 100644 lib/getprogname.h
create mode 100644 m4/getprogname.m4
create mode 100644 modules/getprogname
diff --git a/ChangeLog b/ChangeLog
index ff668a4..05714a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2016-08-18 Pino Toscano <ptoscano(a)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.
+
2016-08-17 Paul Eggert <eggert(a)cs.ucla.edu>
strtod: port errno handling to z/OS
diff --git a/lib/getprogname.c b/lib/getprogname.c
new file mode 100644
index 0000000..ab26283
--- /dev/null
+++ b/lib/getprogname.c
@@ -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
index 0000000..b21e423
--- /dev/null
+++ b/lib/getprogname.h
@@ -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
index 0000000..3d30550
--- /dev/null
+++ b/m4/getprogname.m4
@@ -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
index 0000000..efda4fa
--- /dev/null
+++ b/modules/getprogname
@@ -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
--
2.7.4