... instead of requiring progname to be used (or program_name to be provided). * lib/argmatch.c: Do not include progname.h. [TEST] (program_name): Do not define. [TEST] (main): Call getprogname instead of using program_name. * lib/c-stack.c: Do not include progname.h. (program_name): Do not define. (die): Call getprogname instead of using program_name. * lib/chdir-long.c: Do not include progname.h. [TEST_CHDIR] (main): Do not set program_name. * lib/error.c [!_LIBC]: Include progname.h. [!_LIBC] (program_name): Define using getprogname. * lib/euidaccess.c: Do not include progname.h. [TEST] (main): Do not set program_name. * lib/git-merge-changelog.c: Include getprogname.h instead of progname.h. (usage): Call getprogname instead of using program_name. (main): Likewise. Stop calling set_program_name. * lib/group-member.c: Do not include progname.h. [TEST] (main): Do not set program_name. * modules/argmatch (Depends-on): Add getprogname. * modules/c-stack (Depends-on): Likewise. * modules/error (Depends-on): Likewise. * modules/git-merge-changelog (Depends-on): Likewise. Also remove progname. --- ChangeLog | 26 ++++++++++++++++++++++++++ lib/argmatch.c | 12 +++--------- lib/c-stack.c | 5 ++--- lib/chdir-long.c | 3 --- lib/error.c | 6 +++--- lib/euidaccess.c | 3 --- lib/git-merge-changelog.c | 11 ++++------- lib/group-member.c | 4 ---- modules/argmatch | 1 + modules/c-stack | 1 + modules/error | 1 + modules/git-merge-changelog | 2 +- 12 files changed, 42 insertions(+), 33 deletions(-)
diff --git a/ChangeLog b/ChangeLog index cc37d2a..430d18c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,31 @@ 2016-03-29 Pino Toscano <ptosc...@redhat.com> + Port modules to use getprogname explicitly, instead of requiring + progname to be used (or program_name to be provided). + * lib/argmatch.c: Do not include progname.h. + [TEST] (program_name): Do not define. + [TEST] (main): Call getprogname instead of using program_name. + * lib/c-stack.c: Do not include progname.h. + (program_name): Do not define. + (die): Call getprogname instead of using program_name. + * lib/chdir-long.c: Do not include progname.h. + [TEST_CHDIR] (main): Do not set program_name. + * lib/error.c [!_LIBC]: Include progname.h. + [!_LIBC] (program_name): Define using getprogname. + * lib/euidaccess.c: Do not include progname.h. + [TEST] (main): Do not set program_name. + * lib/git-merge-changelog.c: Include getprogname.h instead of + progname.h. + (usage): Call getprogname instead of using program_name. + (main): Likewise. Stop calling set_program_name. + * lib/group-member.c: Do not include progname.h. + [TEST] (main): Do not set program_name. + * modules/argmatch (Depends-on): Add getprogname. + * modules/c-stack (Depends-on): Likewise. + * modules/error (Depends-on): Likewise. + * modules/git-merge-changelog (Depends-on): Likewise. + Also remove progname. + getprogname: new module This provides a LGPL module for getting the name of the current program, using the same API found on *BSD systems. diff --git a/lib/argmatch.c b/lib/argmatch.c index bd1ad71..40a814f 100644 --- a/lib/argmatch.c +++ b/lib/argmatch.c @@ -35,6 +35,7 @@ #include "error.h" #include "quotearg.h" #include "quote.h" +#include "getprogname.h" #if USE_UNLOCKED_IO # include "unlocked-io.h" @@ -206,11 +207,6 @@ argmatch_to_argument (const char *value, } #ifdef TEST -/* - * Based on "getversion.c" by David MacKenzie <d...@gnu.ai.mit.edu> - */ -char *program_name; - /* When to make backup files. */ enum backup_type { @@ -253,11 +249,9 @@ main (int argc, const char *const *argv) const char *cp; enum backup_type backup_type = no_backups; - program_name = (char *) argv[0]; - if (argc > 2) { - fprintf (stderr, "Usage: %s [VERSION_CONTROL]\n", program_name); + fprintf (stderr, "Usage: %s [VERSION_CONTROL]\n", getprogname ()); exit (1); } @@ -266,7 +260,7 @@ main (int argc, const char *const *argv) backup_args, backup_vals); if (argc == 2) - backup_type = XARGMATCH (program_name, argv[1], + backup_type = XARGMATCH (getprogname (), argv[1], backup_args, backup_vals); printf ("The version control is '%s'\n", diff --git a/lib/c-stack.c b/lib/c-stack.c index baace41..5353c08 100644 --- a/lib/c-stack.c +++ b/lib/c-stack.c @@ -78,6 +78,7 @@ typedef struct sigaltstack stack_t; #include "c-stack.h" #include "exitfail.h" #include "ignore-value.h" +#include "getprogname.h" #if defined SA_ONSTACK && defined SA_SIGINFO # define SIGINFO_WORKS 1 @@ -88,8 +89,6 @@ typedef struct sigaltstack stack_t; # endif #endif -extern char *program_name; - /* The user-specified action to take when a SEGV-related program error or stack overflow occurs. */ static void (* volatile segv_action) (int); @@ -116,7 +115,7 @@ die (int signo) #endif /* !SIGINFO_WORKS && !HAVE_LIBSIGSEGV */ segv_action (signo); message = signo ? program_error_message : stack_overflow_message; - ignore_value (write (STDERR_FILENO, program_name, strlen (program_name))); + ignore_value (write (STDERR_FILENO, getprogname (), strlen (getprogname ()))); ignore_value (write (STDERR_FILENO, ": ", 2)); ignore_value (write (STDERR_FILENO, message, strlen (message))); ignore_value (write (STDERR_FILENO, "\n", 1)); diff --git a/lib/chdir-long.c b/lib/chdir-long.c index 546b4b0..5a039ce 100644 --- a/lib/chdir-long.c +++ b/lib/chdir-long.c @@ -212,8 +212,6 @@ chdir_long (char *dir) # include "closeout.h" # include "error.h" -char *program_name; - int main (int argc, char *argv[]) { @@ -221,7 +219,6 @@ main (int argc, char *argv[]) size_t n = 0; int len; - program_name = argv[0]; atexit (close_stdout); len = getline (&line, &n, stdin); diff --git a/lib/error.c b/lib/error.c index 56ac889..b3b1286 100644 --- a/lib/error.c +++ b/lib/error.c @@ -42,6 +42,8 @@ # define USE_UNLOCKED_IO 0 # define _GL_ATTRIBUTE_FORMAT_PRINTF(a, b) # define _GL_ARG_NONNULL(a) +#else +# include "getprogname.h" #endif #if USE_UNLOCKED_IO @@ -113,9 +115,7 @@ int strerror_r (); # endif # endif -/* The calling program should define program_name and set it to the - name of the executing program. */ -extern char *program_name; +#define program_name getprogname () # if HAVE_STRERROR_R || defined strerror_r # define __strerror_r strerror_r diff --git a/lib/euidaccess.c b/lib/euidaccess.c index 82af941..e9eb0e9 100644 --- a/lib/euidaccess.c +++ b/lib/euidaccess.c @@ -197,8 +197,6 @@ weak_alias (__euidaccess, euidaccess) # include <stdio.h> # include <stdlib.h> -char *program_name; - int main (int argc, char **argv) { @@ -206,7 +204,6 @@ main (int argc, char **argv) int mode; int err; - program_name = argv[0]; if (argc < 3) abort (); file = argv[1]; diff --git a/lib/git-merge-changelog.c b/lib/git-merge-changelog.c index 9d4bd5c..1cbd92b 100644 --- a/lib/git-merge-changelog.c +++ b/lib/git-merge-changelog.c @@ -164,7 +164,6 @@ #include <sys/types.h> #include <unistd.h> -#include "progname.h" #include "error.h" #include "read-file.h" #include "gl_xlist.h" @@ -178,6 +177,7 @@ #include "minmax.h" #include "c-strstr.h" #include "fwriteerror.h" +#include "getprogname.h" #define ASSERT(expr) \ do \ @@ -971,11 +971,11 @@ usage (int status) { if (status != EXIT_SUCCESS) fprintf (stderr, "Try '%s --help' for more information.\n", - program_name); + getprogname ()); else { printf ("Usage: %s [OPTION] O-FILE-NAME A-FILE-NAME B-FILE-NAME\n", - program_name); + getprogname ()); printf ("\n"); printf ("Merges independent modifications of a ChangeLog style file.\n"); printf ("O-FILE-NAME names the original file, the ancestor of the two others.\n"); @@ -1012,9 +1012,6 @@ main (int argc, char *argv[]) bool do_version; bool split_merged_entry; - /* Set program name for messages. */ - set_program_name (argv[0]); - /* Set default values for variables. */ do_help = false; do_version = false; @@ -1041,7 +1038,7 @@ main (int argc, char *argv[]) if (do_version) { /* Version information is requested. */ - printf ("%s\n", program_name); + printf ("%s\n", getprogname ()); printf ("Copyright (C) %s Free Software Foundation, Inc.\n\ License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>\n\ This is free software: you are free to change and redistribute it.\n\ diff --git a/lib/group-member.c b/lib/group-member.c index 365e166..6bbab89 100644 --- a/lib/group-member.c +++ b/lib/group-member.c @@ -97,15 +97,11 @@ group_member (gid_t gid) #ifdef TEST -char *program_name; - int main (int argc, char **argv) { int i; - program_name = argv[0]; - for (i = 1; i < argc; i++) { gid_t gid; diff --git a/modules/argmatch b/modules/argmatch index c28ecaf..1ae3756 100644 --- a/modules/argmatch +++ b/modules/argmatch @@ -15,6 +15,7 @@ verify stdbool stdlib memcmp +getprogname configure.ac: diff --git a/modules/c-stack b/modules/c-stack index 83de3f8..dd303bd 100644 --- a/modules/c-stack +++ b/modules/c-stack @@ -15,6 +15,7 @@ unistd raise sigaction libsigsegv +getprogname configure.ac: gl_C_STACK diff --git a/modules/error b/modules/error index c78e7fe..15fb940 100644 --- a/modules/error +++ b/modules/error @@ -12,6 +12,7 @@ lib/error.c m4/error.m4 Depends-on: +getprogname stdio [test $ac_cv_lib_error_at_line = no] strerror [test $ac_cv_lib_error_at_line = no] unistd [test $ac_cv_lib_error_at_line = no] diff --git a/modules/git-merge-changelog b/modules/git-merge-changelog index 266b652..64c472c 100644 --- a/modules/git-merge-changelog +++ b/modules/git-merge-changelog @@ -8,7 +8,6 @@ Depends-on: getopt-gnu stdbool stdlib -progname error read-file xlist @@ -24,6 +23,7 @@ c-strstr fwriteerror memchr memcmp +getprogname configure.ac: -- 2.5.5