summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPino Toscano <ptoscano@redhat.com>2016-08-18 15:18:23 +0200
committerJim Meyering <meyering@fb.com>2016-09-05 09:21:54 -0700
commitf29814b96c9737abc8193d57d630697700feebeb (patch)
tree8c4505532adb10e16fa8965d7fc993a06f867388
parent653a5be9759c9757a2509dad5057064e97899517 (diff)
downloadgnulib-f29814b96c9737abc8193d57d630697700feebeb.tar.gz
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.
-rw-r--r--ChangeLog28
-rw-r--r--lib/argmatch.c8
-rw-r--r--lib/c-stack.c5
-rw-r--r--lib/chdir-long.c3
-rw-r--r--lib/error.c6
-rw-r--r--lib/euidaccess.c3
-rw-r--r--lib/git-merge-changelog.c11
-rw-r--r--lib/group-member.c4
-rw-r--r--modules/argmatch1
-rw-r--r--modules/c-stack1
-rw-r--r--modules/error1
-rw-r--r--modules/git-merge-changelog2
12 files changed, 44 insertions, 29 deletions
diff --git a/ChangeLog b/ChangeLog
index dde0c72598..467f04134a 100644
--- 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.
diff --git a/lib/argmatch.c b/lib/argmatch.c
index bd1ad71f5b..bf3cddfb85 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"
@@ -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",
diff --git a/lib/c-stack.c b/lib/c-stack.c
index baace4175c..5353c08660 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 546b4b0653..5a039ced88 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 56ac889aa5..b3b1286a35 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 82af9417ac..e9eb0e948a 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 9d4bd5c809..1cbd92b15d 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 365e166921..6bbab893c7 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 c28ecaf2f1..1ae3756453 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 83de3f8bad..dd303bd7ca 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 c78e7fe409..15fb94093c 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 266b6529ba..64c472ce50 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: