From 653a5be9759c9757a2509dad5057064e97899517 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 18 Aug 2016 15:18:22 +0200 Subject: [PATCH] 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. * NEWS: Document the deprecation of the 'progname' module. --- ChangeLog | 13 +++++++++++++ MODULES.html.sh | 1 + NEWS | 8 ++++++++ lib/getprogname.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ lib/getprogname.h | 34 ++++++++++++++++++++++++++++++++++ m4/getprogname.m4 | 13 +++++++++++++ modules/getprogname | 28 ++++++++++++++++++++++++++++ 7 files changed, 142 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 ba3e04817e..dde0c72598 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2016-09-05 Pino Toscano + + * NEWS: Document the deprecation of the 'progname' module. + +2016-08-18 Pino Toscano + + 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 manywarnings: add -fno-common diff --git a/MODULES.html.sh b/MODULES.html.sh index f1248386cb..ec6f300553 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -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 e33d350146..ac302b59ae 100644 --- 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 index 0000000000..ab2628388e --- /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 . */ + +#include + +/* Specification. */ +#include "getprogname.h" + +#include /* get program_invocation_name declaration */ +#include + + +#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 0000000000..b21e4232b5 --- /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 . */ + +#ifndef _GL_GETPROGNAME_H +#define _GL_GETPROGNAME_H + +#include + +#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 0000000000..3d305502aa --- /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 0000000000..efda4fa24f --- /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 ]) +AC_CHECK_DECLS([program_invocation_short_name], [], [], [#include ]) + +Makefile.am: +lib_SOURCES += getprogname.h getprogname.c + +Include: +"getprogname.h" + +License: +LGPL + +Maintainer: +All -- 2.39.5