]> Savannah Git Hosting - gnulib.git/commitdiff
Port modules to use getprogname explicitly
authorPino Toscano <ptoscano@redhat.com>
Thu, 18 Aug 2016 13:18:23 +0000 (15:18 +0200)
committerJim Meyering <meyering@fb.com>
Mon, 5 Sep 2016 16:21:54 +0000 (09:21 -0700)
... 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.

12 files changed:
ChangeLog
lib/argmatch.c
lib/c-stack.c
lib/chdir-long.c
lib/error.c
lib/euidaccess.c
lib/git-merge-changelog.c
lib/group-member.c
modules/argmatch
modules/c-stack
modules/error
modules/git-merge-changelog

index dde0c725984c01837109c39e9a6d7bb4b8367b1a..467f04134ae3f651c7a324f1b7de46a86e8d0d98 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,31 @@
+2016-08-18  Pino Toscano  <ptoscano@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.
+
 2016-09-05  Pino Toscano  <ptoscano@redhat.com>
 
        * NEWS: Document the deprecation of the 'progname' module.
index bd1ad71f5b57bf917020410f504e4850787c1bf1..bf3cddfb85542e2de5e04cf28a183741c14a369f 100644 (file)
@@ -35,6 +35,7 @@
 #include "error.h"
 #include "quotearg.h"
 #include "quote.h"
+#include "getprogname.h"
 
 #if USE_UNLOCKED_IO
 # include "unlocked-io.h"
@@ -209,7 +210,6 @@ argmatch_to_argument (const char *value,
 /*
  * Based on "getversion.c" by David MacKenzie <djm@gnu.ai.mit.edu>
  */
-char *program_name;
 
 /* When to make backup files.  */
 enum backup_type
@@ -253,11 +253,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 +264,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",
index baace4175c9456c0bd3bfc9ce3c8fc99d517192f..5353c08660d3e8d00e11a53f8af04e8a1f317a02 100644 (file)
@@ -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));
index 546b4b06538499ac45e44ac25733e96f5a99fc60..5a039ced88157e9695f3d9ab82584ac9d39573eb 100644 (file)
@@ -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);
index 56ac889aa5457d71935d8087614c3f0739f0e052..b3b1286a350b1c24a853cf141818f54bb623ab5e 100644 (file)
@@ -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
index 82af9417ac39f3d46ecff8c117f7bbdb703ab6b6..e9eb0e948a3cba41b49b2925d403e6d0f3b1a4d9 100644 (file)
@@ -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];
index 9d4bd5c809d7bd0724a535a1da22ccb5e831d38e..1cbd92b15dffcceb52b8ec2b519d8cd0fe2302b3 100644 (file)
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "progname.h"
 #include "error.h"
 #include "read-file.h"
 #include "gl_xlist.h"
 #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\
index 365e1669216dbf67ce9b0c2310d958f01292381d..6bbab893c7e57e1ac1cffb285bfbb93ed721b6a5 100644 (file)
@@ -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;
index c28ecaf2f1c4de51dd7c2358e0b217b9f3afd8ce..1ae3756453ffa60b7aebfef470abffa7d0220fe8 100644 (file)
@@ -15,6 +15,7 @@ verify
 stdbool
 stdlib
 memcmp
+getprogname
 
 configure.ac:
 
index 83de3f8bad5f0593072b604949c4931a206df09b..dd303bd7ca7080e812638b8d7f350c49ca15d217 100644 (file)
@@ -15,6 +15,7 @@ unistd
 raise
 sigaction
 libsigsegv
+getprogname
 
 configure.ac:
 gl_C_STACK
index c78e7fe409a7884ca78c93d90d58108031ac5fb1..15fb94093c7cbe7ad1e73507d12679f72597fdec 100644 (file)
@@ -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]
index 266b6529bafe2b49506cd9ca003542abe95ccf26..64c472ce50f2b4f2ea563c074c1dfd37068d467d 100644 (file)
@@ -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: