From 896b672499d6a31a6caf85411bcbdde6edc57668 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Tue, 3 Jun 2008 08:34:09 +0200 Subject: [PATCH] use gnulib's progname module * bootstrap.conf (gnulib_modules): Add progname. * src/*.c (program_name): Remove declaration. * (main): Call set_program_name rather than setting program_name. * src/nice.c (main): Cast program_name to "(char *)". * src/prog-fprintf.c: Include "system.h" * src/system.h: Include "progname.h". * maint.mk (sc_program_name): Adjust rule. Suggestion from Eric Blake. --- bootstrap.conf | 1 + maint.mk | 6 +++--- src/base64.c | 5 +---- src/basename.c | 5 +---- src/cat.c | 5 +---- src/chcon.c | 5 +---- src/chgrp.c | 5 +---- src/chmod.c | 5 +---- src/chown.c | 5 +---- src/chroot.c | 5 +---- src/cksum.c | 5 +---- src/comm.c | 5 +---- src/copy.c | 3 --- src/cp.c | 5 +---- src/csplit.c | 5 +---- src/cut.c | 5 +---- src/date.c | 5 +---- src/dd.c | 5 +---- src/df.c | 5 +---- src/dircolors.c | 4 +--- src/dirname.c | 5 +---- src/du.c | 5 +---- src/echo.c | 5 +---- src/env.c | 5 +---- src/expand.c | 5 +---- src/expr.c | 5 +---- src/factor.c | 5 +---- src/fmt.c | 5 +---- src/fold.c | 5 +---- src/groups.c | 5 +---- src/head.c | 5 +---- src/hostid.c | 5 +---- src/hostname.c | 5 +---- src/id.c | 5 +---- src/install.c | 5 +---- src/join.c | 5 +---- src/kill.c | 5 +---- src/link.c | 5 +---- src/ln.c | 5 +---- src/logname.c | 5 +---- src/ls.c | 5 +---- src/md5sum.c | 5 +---- src/mkdir.c | 5 +---- src/mkfifo.c | 5 +---- src/mknod.c | 5 +---- src/mktemp.c | 5 +---- src/mv.c | 5 +---- src/nice.c | 7 ++----- src/nl.c | 5 +---- src/nohup.c | 4 +--- src/od.c | 5 +---- src/paste.c | 5 +---- src/pathchk.c | 5 +---- src/pinky.c | 5 +---- src/pr.c | 5 +---- src/printenv.c | 5 +---- src/printf.c | 5 +---- src/prog-fprintf.c | 4 ++-- src/ptx.c | 5 +---- src/pwd.c | 5 +---- src/readlink.c | 5 +---- src/remove.c | 2 -- src/rm.c | 5 +---- src/rmdir.c | 5 +---- src/runcon.c | 5 +---- src/seq.c | 5 +---- src/setuidgid.c | 4 +--- src/shred.c | 5 +---- src/shuf.c | 5 +---- src/sleep.c | 5 +---- src/sort.c | 5 +---- src/split.c | 5 +---- src/stat.c | 4 +--- src/stty.c | 5 +---- src/su.c | 5 +---- src/sum.c | 5 +---- src/sync.c | 5 +---- src/system.h | 2 ++ src/tac.c | 5 +---- src/tail.c | 5 +---- src/tee.c | 5 +---- src/test.c | 4 +--- src/timeout.c | 4 +--- src/touch.c | 5 +---- src/tr.c | 5 +---- src/true.c | 5 +---- src/tsort.c | 5 +---- src/tty.c | 5 +---- src/uname.c | 5 +---- src/unexpand.c | 5 +---- src/uniq.c | 5 +---- src/unlink.c | 5 +---- src/uptime.c | 5 +---- src/users.c | 5 +---- src/wc.c | 5 +---- src/who.c | 5 +---- src/whoami.c | 5 +---- src/yes.c | 5 +---- 98 files changed, 101 insertions(+), 373 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 7b5be83..5685ad5 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -70,6 +70,7 @@ gnulib_modules=" posix-shell posixtm posixver + progname propername putenv quote quotearg raise readlink areadlink-with-size diff --git a/maint.mk b/maint.mk index 25551a8..f4b0bae 100644 --- a/maint.mk +++ b/maint.mk @@ -342,13 +342,13 @@ sc_system_h_headers: .re-list fi # Ensure that each .c file containing a "main" function also -# declares "char *program_name", with or without "const". +# calls set_program_name. sc_program_name: @if $(VC_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then \ files=$$(grep -l '^main *(' $$($(VC_LIST_EXCEPT) | grep '\.c$$')); \ - grep -EL '^(char const|(const )?char) \*program_name;' $$files \ + grep -LE 'set_program_name *\(m?argv\[0\]\);' $$files \ | grep . && \ - { echo '$(ME): the above files do not declare program_name' \ + { echo '$(ME): the above files do not call set_program_name' \ 1>&2; exit 1; } || :; \ else :; \ fi diff --git a/src/base64.c b/src/base64.c index fd9d114..3e66c12 100644 --- a/src/base64.c +++ b/src/base64.c @@ -37,9 +37,6 @@ #define AUTHORS proper_name ("Simon Josefsson") -/* The invocation name of this program. */ -char const *program_name; - static const struct option long_options[] = { {"decode", no_argument, 0, 'd'}, {"wrap", required_argument, 0, 'w'}, @@ -248,7 +245,7 @@ main (int argc, char **argv) uintmax_t wrap_column = 76; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/basename.c b/src/basename.c index fe056fc..38e8879 100644 --- a/src/basename.c +++ b/src/basename.c @@ -39,9 +39,6 @@ #define AUTHORS proper_name ("FIXME unknown") -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -99,7 +96,7 @@ main (int argc, char **argv) char *name; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/cat.c b/src/cat.c index fd6c9df..d762f45 100644 --- a/src/cat.c +++ b/src/cat.c @@ -51,9 +51,6 @@ #undef max #define max(h,i) ((h) > (i) ? (h) : (i)) -/* Name under which this program was invoked. */ -char const *program_name; - /* Name of input file. May be "-". */ static char const *infile; @@ -565,7 +562,7 @@ main (int argc, char **argv) }; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/chcon.c b/src/chcon.c index dacce2b..659664e 100644 --- a/src/chcon.c +++ b/src/chcon.c @@ -55,9 +55,6 @@ enum Verbosity V_off }; -/* The name the program was run with. */ -char const *program_name; - /* If nonzero, and the systems has support for it, change the context of symbolic links rather than any files they point to. */ static bool affect_symlink_referent; @@ -426,7 +423,7 @@ main (int argc, char **argv) int optc; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/chgrp.c b/src/chgrp.c index c42fad8..db83c59 100644 --- a/src/chgrp.c +++ b/src/chgrp.c @@ -42,9 +42,6 @@ # define endgrent() ((void) 0) #endif -/* The name the program was run with. */ -char const *program_name; - /* The argument to the --reference option. Use the group ID of this file. This file must exist. */ static char *reference_file; @@ -184,7 +181,7 @@ main (int argc, char **argv) int optc; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/chmod.c b/src/chmod.c index 8002ef5..80fc363 100644 --- a/src/chmod.c +++ b/src/chmod.c @@ -58,9 +58,6 @@ enum Verbosity V_off }; -/* The name the program was run with. */ -char const *program_name; - /* The desired change to the mode. */ static struct mode_change *change; @@ -394,7 +391,7 @@ main (int argc, char **argv) int c; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/chown.c b/src/chown.c index 02e0148..e5740d2 100644 --- a/src/chown.c +++ b/src/chown.c @@ -47,9 +47,6 @@ proper_name ("David MacKenzie"), \ proper_name ("Jim Meyering") -/* The name the program was run with. */ -char const *program_name; - /* The argument to the --reference option. Use the owner and group IDs of this file. This file must exist. */ static char *reference_file; @@ -186,7 +183,7 @@ main (int argc, char **argv) int optc; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/chroot.c b/src/chroot.c index 8081b16..399f76c 100644 --- a/src/chroot.c +++ b/src/chroot.c @@ -32,9 +32,6 @@ #define AUTHORS proper_name ("Roland McGrath") -/* The name this program was run with, for error messages. */ -char const *program_name; - void usage (int status) { @@ -66,7 +63,7 @@ int main (int argc, char **argv) { initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/cksum.c b/src/cksum.c index 6f11514..ce6e9c0 100644 --- a/src/cksum.c +++ b/src/cksum.c @@ -113,9 +113,6 @@ main (void) /* Number of bytes to read at once. */ # define BUFLEN (1 << 16) -/* The name this program was run with. */ -char const *program_name; - static uint_fast32_t const crctab[256] = { 0x00000000, @@ -284,7 +281,7 @@ main (int argc, char **argv) bool ok; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/comm.c b/src/comm.c index 4700ca0..a71d61a 100644 --- a/src/comm.c +++ b/src/comm.c @@ -39,9 +39,6 @@ #undef min #define min(x, y) ((x) < (y) ? (x) : (y)) -/* The name this program was run with. */ -char const *program_name; - /* True if the LC_COLLATE locale is hard. */ static bool hard_LC_COLLATE; @@ -230,7 +227,7 @@ main (int argc, char **argv) int c; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/copy.c b/src/copy.c index 7d33cb3..82c6978 100644 --- a/src/copy.c +++ b/src/copy.c @@ -107,9 +107,6 @@ static bool owner_failure_ok (struct cp_options const *x); static char const *top_level_src_name; static char const *top_level_dst_name; -/* The invocation name of this program. */ -extern char *program_name; - /* FIXME: describe */ /* FIXME: rewrite this to use a hash table so we avoid the quadratic performance hit that's probably noticeable only on trees deeper diff --git a/src/cp.c b/src/cp.c index 6630449..01b9c18 100644 --- a/src/cp.c +++ b/src/cp.c @@ -88,9 +88,6 @@ enum /* Initial number of entries in the inode hash table. */ #define INITIAL_ENTRY_TAB_SIZE 70 -/* The invocation name of this program. */ -char const *program_name; - /* True if the kernel is SELinux enabled. */ static bool selinux_enabled; @@ -898,7 +895,7 @@ main (int argc, char **argv) bool no_target_directory = false; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/csplit.c b/src/csplit.c index 7d9904c..7e63ca8 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -128,9 +128,6 @@ static void delete_all_files (bool); static void save_line_to_file (const struct cstring *line); void usage (int status); -/* The name this program was run with. */ -char const *program_name; - /* Start of buffer list. */ static struct buffer_record *head = NULL; @@ -1330,7 +1327,7 @@ main (int argc, char **argv) unsigned long int val; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/cut.c b/src/cut.c index a91cca7..0e151fd 100644 --- a/src/cut.c +++ b/src/cut.c @@ -120,9 +120,6 @@ enum operating_mode field_mode }; -/* The name this program was run with. */ -char const *program_name; - static enum operating_mode operating_mode; /* If true do not output lines containing no delimeter characters. @@ -762,7 +759,7 @@ main (int argc, char **argv) char *spec_list_string IF_LINT(= NULL); initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/date.c b/src/date.c index 36b2826..86b3225 100644 --- a/src/date.c +++ b/src/date.c @@ -77,9 +77,6 @@ ARGMATCH_VERIFY (time_spec_string, time_spec); /* A format suitable for Internet RFC 2822. */ static char const rfc_2822_format[] = "%a, %d %b %Y %H:%M:%S %z"; -/* The name this program was run with, for error messages. */ -char const *program_name; - /* For long options that have no equivalent short option, use a non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum @@ -325,7 +322,7 @@ main (int argc, char **argv) int option_specified_date; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/dd.c b/src/dd.c index 947e687..ead9574 100644 --- a/src/dd.c +++ b/src/dd.c @@ -128,9 +128,6 @@ enum STATUS_NOXFER = 01 }; -/* The name this program was run with. */ -char const *program_name; - /* The name of the input file, or NULL for the standard input. */ static char const *input_file = NULL; @@ -1671,7 +1668,7 @@ main (int argc, char **argv) off_t offset; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/df.c b/src/df.c index 2b320cf..66e9207 100644 --- a/src/df.c +++ b/src/df.c @@ -42,9 +42,6 @@ proper_name ("David MacKenzie"), \ proper_name ("Paul Eggert") -/* Name this program was run with. */ -char const *program_name; - /* If true, show inode information. */ static bool inode_format; @@ -781,7 +778,7 @@ main (int argc, char **argv) struct stat *stats IF_LINT (= 0); initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/dircolors.c b/src/dircolors.c index 55cbd26..44ec537 100644 --- a/src/dircolors.c +++ b/src/dircolors.c @@ -87,8 +87,6 @@ static struct option const long_options[] = {NULL, 0, NULL, 0} }; -char const *program_name; - void usage (int status) { @@ -402,7 +400,7 @@ main (int argc, char **argv) bool print_database = false; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/dirname.c b/src/dirname.c index 3c93d03..3a31912 100644 --- a/src/dirname.c +++ b/src/dirname.c @@ -35,9 +35,6 @@ proper_name ("David MacKenzie"), \ proper_name ("Jim Meyering") -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -78,7 +75,7 @@ main (int argc, char **argv) size_t len; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/du.c b/src/du.c index 8b04b65..32cb363 100644 --- a/src/du.c +++ b/src/du.c @@ -126,9 +126,6 @@ struct dulevel struct duinfo subdir; }; -/* Name under which this program was invoked. */ -char const *program_name; - /* If true, display counts for all files, not just directories. */ static bool opt_all = false; @@ -685,7 +682,7 @@ main (int argc, char **argv) cwd_only[1] = NULL; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/echo.c b/src/echo.c index 4b8f560..ebbf5b8 100644 --- a/src/echo.c +++ b/src/echo.c @@ -50,9 +50,6 @@ on System V systems with the -E option. enum { DEFAULT_ECHO_TO_XPG = false }; #endif -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -134,7 +131,7 @@ main (int argc, char **argv) bool do_v9 = DEFAULT_ECHO_TO_XPG; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/env.c b/src/env.c index 5103cc9..67e411f 100644 --- a/src/env.c +++ b/src/env.c @@ -96,9 +96,6 @@ int putenv (); extern char **environ; -/* The name by which this program was run. */ -char const *program_name; - static struct option const longopts[] = { {"ignore-environment", no_argument, NULL, 'i'}, @@ -143,7 +140,7 @@ main (int argc, char **argv) bool ignore_environment = false; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/expand.c b/src/expand.c index 2cce8fb..8efb81b 100644 --- a/src/expand.c +++ b/src/expand.c @@ -51,9 +51,6 @@ allocated for the output line. */ #define OUTPUT_BLOCK 256 -/* The name this program was run with. */ -char const *program_name; - /* If true, convert blanks even after nonblank characters have been read on the line. */ static bool convert_entire_line; @@ -370,7 +367,7 @@ main (int argc, char **argv) int c; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/expr.c b/src/expr.c index e658402..d6b1985 100644 --- a/src/expr.c +++ b/src/expr.c @@ -81,9 +81,6 @@ typedef struct valinfo VALUE; /* The arguments given to the program, minus the program name. */ static char **args; -/* The name this program was run with. */ -char const *program_name; - static VALUE *eval (bool); static bool nomoreargs (void); static bool null (VALUE *v); @@ -188,7 +185,7 @@ main (int argc, char **argv) VALUE *v; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/factor.c b/src/factor.c index 681db36..f46953c 100644 --- a/src/factor.c +++ b/src/factor.c @@ -59,9 +59,6 @@ static const unsigned char wheel_tab[] = #define WHEEL_START (wheel_tab + WHEEL_SIZE) #define WHEEL_END (wheel_tab + (sizeof wheel_tab / sizeof wheel_tab[0])) -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -192,7 +189,7 @@ main (int argc, char **argv) bool ok; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/fmt.c b/src/fmt.c index 1f4e1da..708e60b 100644 --- a/src/fmt.c +++ b/src/fmt.c @@ -167,9 +167,6 @@ static void put_line (WORD *w, int indent); static void put_word (WORD *w); static void put_space (int space); -/* The name this program was run with. */ -char const *program_name; - /* Option values. */ /* If true, first 2 lines may have different indent (default false). */ @@ -324,7 +321,7 @@ main (int argc, char **argv) char const *max_width_option = NULL; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/fold.c b/src/fold.c index 8d63a8b..57ff123 100644 --- a/src/fold.c +++ b/src/fold.c @@ -34,9 +34,6 @@ #define AUTHORS proper_name ("David MacKenzie") -/* The name this program was run with. */ -char const *program_name; - /* If nonzero, try to break on whitespace. */ static bool break_spaces; @@ -247,7 +244,7 @@ main (int argc, char **argv) bool ok; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/groups.c b/src/groups.c index c67ac6e..ef96400 100644 --- a/src/groups.c +++ b/src/groups.c @@ -29,9 +29,6 @@ #include "error.h" #include "group-list.h" -/* The name this program was run with. */ -char const *program_name; - /* The official name of this program (e.g., no `g' prefix). */ #define PROGRAM_NAME "groups" @@ -76,7 +73,7 @@ main (int argc, char **argv) uid_t ruid; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/head.c b/src/head.c index a52f151..7a0e2ad 100644 --- a/src/head.c +++ b/src/head.c @@ -64,9 +64,6 @@ enum header_mode multiple_files, always, never }; -/* The name this program was run with. */ -char const *program_name; - /* Have we ever read standard input? */ static bool have_read_stdin; @@ -920,7 +917,7 @@ main (int argc, char **argv) char const *const *file_list; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/hostid.c b/src/hostid.c index e481c1c..dbcb98d 100644 --- a/src/hostid.c +++ b/src/hostid.c @@ -33,9 +33,6 @@ #define AUTHORS proper_name ("Jim Meyering") -/* The name this program was run with, for error messages. */ -char const *program_name; - void usage (int status) { @@ -64,7 +61,7 @@ main (int argc, char **argv) unsigned int id; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/hostname.c b/src/hostname.c index 23aab17..cf8e953 100644 --- a/src/hostname.c +++ b/src/hostname.c @@ -50,9 +50,6 @@ sethostname (char *name, size_t namelen) # define HAVE_SETHOSTNAME 1 /* Now we have it... */ #endif -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -81,7 +78,7 @@ main (int argc, char **argv) char *hostname; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/id.c b/src/id.c index 53cb0f4..14b558d 100644 --- a/src/id.c +++ b/src/id.c @@ -44,9 +44,6 @@ static int just_context = 0; static void print_user (uid_t uid); static void print_full_info (const char *username); -/* The name this program was run with. */ -char const *program_name; - /* If true, output user/group name instead of ID number. -n */ static bool use_name = false; @@ -121,7 +118,7 @@ main (int argc, char **argv) bool just_user = false; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/install.c b/src/install.c index decdd7d..aa14b94 100644 --- a/src/install.c +++ b/src/install.c @@ -96,9 +96,6 @@ static int make_ancestor (char const *dir, char const *component, void *options); void usage (int status); -/* The name this program was run with, for error messages. */ -char const *program_name; - /* The user name that will own the files, or NULL to make the owner the current user ID. */ static char *owner_name; @@ -338,7 +335,7 @@ main (int argc, char **argv) selinux_enabled = (0 < is_selinux_enabled ()); initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/join.c b/src/join.c index 111f971..3287268 100644 --- a/src/join.c +++ b/src/join.c @@ -79,9 +79,6 @@ struct seq struct line *lines; }; -/* The name this program was run with. */ -char const *program_name; - /* The previous line read from each file. */ static struct line *prevline[2]; @@ -934,7 +931,7 @@ main (int argc, char **argv) int i; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/kill.c b/src/kill.c index 2179907..1fd4958 100644 --- a/src/kill.c +++ b/src/kill.c @@ -60,9 +60,6 @@ # endif #endif -/* The name this program was run with, for error messages. */ -char const *program_name; - static char const short_options[] = "0::1::2::3::4::5::6::7::8::9::" "A::B::C::D::E::F::G::H::I::J::K::L::M::" @@ -241,7 +238,7 @@ main (int argc, char **argv) char signame[SIG2STR_MAX]; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/link.c b/src/link.c index eeb79e7..1b09fe3 100644 --- a/src/link.c +++ b/src/link.c @@ -35,9 +35,6 @@ #define AUTHORS proper_name ("Michael Stone") -/* Name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -63,7 +60,7 @@ int main (int argc, char **argv) { initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/ln.c b/src/ln.c index 4b9c994..1372240 100644 --- a/src/ln.c +++ b/src/ln.c @@ -57,9 +57,6 @@ lstat (File, Stat_buf) #endif -/* The name by which the program was run, for error messages. */ -char const *program_name; - /* FIXME: document */ static enum backup_type backup_type; @@ -423,7 +420,7 @@ main (int argc, char **argv) char **file; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/logname.c b/src/logname.c index ec894e2..a71ac33 100644 --- a/src/logname.c +++ b/src/logname.c @@ -29,9 +29,6 @@ #define AUTHORS proper_name ("FIXME: unknown") -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -58,7 +55,7 @@ main (int argc, char **argv) char *cp; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/ls.c b/src/ls.c index 9a8ad2d..600d7a5 100644 --- a/src/ls.c +++ b/src/ls.c @@ -244,9 +244,6 @@ static void sort_files (void); static void parse_ls_color (void); void usage (int status); -/* The name this program was run with. */ -char const *program_name; - /* Initial size of hash table. Most hierarchies are likely to be shallower than this. */ #define INITIAL_TABLE_SIZE 30 @@ -1150,7 +1147,7 @@ main (int argc, char **argv) #endif initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/md5sum.c b/src/md5sum.c index 3584972..dcafe97 100644 --- a/src/md5sum.c +++ b/src/md5sum.c @@ -120,9 +120,6 @@ static bool warn = false; /* With --check, suppress the "OK" printed for each verified file. */ static bool quiet = false; -/* The name this program was run with. */ -char const *program_name; - /* For long options that have no equivalent short option, use a non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum @@ -613,7 +610,7 @@ main (int argc, char **argv) /* Setting values of global variables. */ initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/mkdir.c b/src/mkdir.c index c2d52de..9644f4c 100644 --- a/src/mkdir.c +++ b/src/mkdir.c @@ -36,9 +36,6 @@ #define AUTHORS proper_name ("David MacKenzie") -/* The name this program was run with. */ -char const *program_name; - static struct option const longopts[] = { {GETOPT_SELINUX_CONTEXT_OPTION_DECL}, @@ -153,7 +150,7 @@ main (int argc, char **argv) options.created_directory_format = NULL; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/mkfifo.c b/src/mkfifo.c index 5befd45..d0d2c45 100644 --- a/src/mkfifo.c +++ b/src/mkfifo.c @@ -32,9 +32,6 @@ #define AUTHORS proper_name ("David MacKenzie") -/* The name this program was run with. */ -char const *program_name; - static struct option const longopts[] = { {GETOPT_SELINUX_CONTEXT_OPTION_DECL}, @@ -83,7 +80,7 @@ main (int argc, char **argv) security_context_t scontext = NULL; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/mknod.c b/src/mknod.c index 0cd2d27..d93e2cb 100644 --- a/src/mknod.c +++ b/src/mknod.c @@ -33,9 +33,6 @@ #define AUTHORS proper_name ("David MacKenzie") -/* The name this program was run with. */ -char const *program_name; - static struct option const longopts[] = { {GETOPT_SELINUX_CONTEXT_OPTION_DECL}, @@ -100,7 +97,7 @@ main (int argc, char **argv) security_context_t scontext = NULL; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/mktemp.c b/src/mktemp.c index 114fdc2..8a09231 100644 --- a/src/mktemp.c +++ b/src/mktemp.c @@ -35,9 +35,6 @@ static const char *default_template = "tmp.XXXXXXXXXX"; -/* The name this program was run with. */ -char const *program_name; - /* For long options that have no equivalent short option, use a non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum @@ -144,7 +141,7 @@ main (int argc, char **argv) char *dest_name; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/mv.c b/src/mv.c index 090541a..bab26ba 100644 --- a/src/mv.c +++ b/src/mv.c @@ -56,9 +56,6 @@ enum STRIP_TRAILING_SLASHES_OPTION }; -/* The name this program was run with. */ -char const *program_name; - /* Remove any trailing slashes from each SOURCE argument. */ static bool remove_trailing_slashes; @@ -364,7 +361,7 @@ main (int argc, char **argv) char **file; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/nice.c b/src/nice.c index 3981a71..1dcb3a3 100644 --- a/src/nice.c +++ b/src/nice.c @@ -55,9 +55,6 @@ # define NZERO 20 #endif -/* The name this program was run with. */ -char const *program_name; - static struct option const longopts[] = { {"adjustment", required_argument, NULL, 'n'}, @@ -99,7 +96,7 @@ main (int argc, char **argv) int i; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); @@ -126,7 +123,7 @@ main (int argc, char **argv) char **fake_argv = argv + (i - 1); /* Ensure that any getopt diagnostics use the right name. */ - fake_argv[0] = program_name; + fake_argv[0] = (char *) program_name; /* Initialize getopt_long's internal state. */ optind = 0; diff --git a/src/nl.c b/src/nl.c index 24e9f98..ddd0fcf 100644 --- a/src/nl.c +++ b/src/nl.c @@ -61,9 +61,6 @@ enum section Header, Body, Footer, Text }; -/* The name this program was run with. */ -char const *program_name; - /* Format of body lines (-b). */ static char const *body_type = "t"; @@ -460,7 +457,7 @@ main (int argc, char **argv) bool ok = true; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/nohup.c b/src/nohup.c index da639f2..61f181d 100644 --- a/src/nohup.c +++ b/src/nohup.c @@ -43,8 +43,6 @@ enum NOHUP_FAILURE = 127 }; -char const *program_name; - void usage (int status) { @@ -89,7 +87,7 @@ main (int argc, char **argv) bool redirecting_stderr; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/od.c b/src/od.c index 9b2f722..3273ec2 100644 --- a/src/od.c +++ b/src/od.c @@ -113,9 +113,6 @@ struct tspec int field_width; }; -/* The name this program was run with. */ -char const *program_name; - /* Convert the number of 8-bit bytes of a binary representation to the number of characters (digits + sign if the type is signed) required to represent the same quantity in the specified base/type. @@ -1565,7 +1562,7 @@ main (int argc, char **argv) uintmax_t pseudo_start IF_LINT (= 0); initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/paste.c b/src/paste.c index cc61a09..9dee94a 100644 --- a/src/paste.c +++ b/src/paste.c @@ -54,9 +54,6 @@ /* Indicates that no delimiter should be added in the current position. */ #define EMPTY_DELIM '\0' -/* Name this program was run with. */ -char const *program_name; - /* If nonzero, we have read standard input at some point. */ static bool have_read_stdin; @@ -466,7 +463,7 @@ main (int argc, char **argv) char const *delim_arg = "\t"; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/pathchk.c b/src/pathchk.c index 821fe33..48001fc 100644 --- a/src/pathchk.c +++ b/src/pathchk.c @@ -71,9 +71,6 @@ static bool validate_file_name (char *, bool, bool); -/* The name this program was run with. */ -char const *program_name; - /* For long options that have no equivalent short option, use a non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum @@ -121,7 +118,7 @@ main (int argc, char **argv) int optc; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/pinky.c b/src/pinky.c index b8d453b..9c80d94 100644 --- a/src/pinky.c +++ b/src/pinky.c @@ -44,9 +44,6 @@ char *ttyname (); -/* The name this program was run with. */ -char const *program_name; - /* If true, display the hours:minutes since each user has touched the keyboard, or blank if within the last minute, or days followed by a 'd' if not within the last day. */ @@ -544,7 +541,7 @@ main (int argc, char **argv) int n_users; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/pr.c b/src/pr.c index 28ce713..27ff859 100644 --- a/src/pr.c +++ b/src/pr.c @@ -445,9 +445,6 @@ static void cleanup (void); static void print_sep_string (void); static void separator_string (const char *optarg_S); -/* The name under which this program was invoked. */ -char const *program_name; - /* All of the columns to print. */ static COLUMN *column_vector; @@ -869,7 +866,7 @@ main (int argc, char **argv) size_t n_alloc = 0; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/printenv.c b/src/printenv.c index b90551c..b68fb21 100644 --- a/src/printenv.c +++ b/src/printenv.c @@ -45,9 +45,6 @@ enum { PRINTENV_FAILURE = 2 }; proper_name ("David MacKenzie"), \ proper_name ("Richard Mlynarik") -/* The name this program was run with. */ -char const *program_name; - extern char **environ; void @@ -82,7 +79,7 @@ main (int argc, char **argv) bool ok; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/printf.c b/src/printf.c index 7081dcc..a9d5aa1 100644 --- a/src/printf.c +++ b/src/printf.c @@ -78,9 +78,6 @@ static bool posixly_correct; static char const *const cfcc_msg = N_("warning: %s: character(s) following character constant have been ignored"); -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -637,7 +634,7 @@ main (int argc, char **argv) int args_used; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/prog-fprintf.c b/src/prog-fprintf.c index 85aceb6..cbf7bec 100644 --- a/src/prog-fprintf.c +++ b/src/prog-fprintf.c @@ -18,9 +18,9 @@ #include #include -#include "prog-fprintf.h" +#include "system.h" -extern char *program_name; +#include "prog-fprintf.h" /* Display program name followed by variable list. Used for e.g. verbose output */ diff --git a/src/ptx.c b/src/ptx.c index cdc6513..28dfc87 100644 --- a/src/ptx.c +++ b/src/ptx.c @@ -68,9 +68,6 @@ /* Imported from "regex.c". */ #define Sword 1 -/* The name this program was run with. */ -char const *program_name; - /* Program options. */ enum Format @@ -1980,7 +1977,7 @@ main (int argc, char **argv) /* Decode program options. */ initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/pwd.c b/src/pwd.c index adbc5b3..5038065 100644 --- a/src/pwd.c +++ b/src/pwd.c @@ -39,9 +39,6 @@ struct file_name char *start; }; -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -289,7 +286,7 @@ main (int argc, char **argv) char *wd; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/readlink.c b/src/readlink.c index 455b56e..98a955c 100644 --- a/src/readlink.c +++ b/src/readlink.c @@ -32,9 +32,6 @@ #define AUTHORS proper_name ("Dmitry V. Levin") -/* Name this program was run with. */ -char const *program_name; - /* If true, do not output the trailing newline. */ static bool no_newline; @@ -105,7 +102,7 @@ main (int argc, char **argv) int optc; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/remove.c b/src/remove.c index 07c2f71..4c3ee99 100644 --- a/src/remove.c +++ b/src/remove.c @@ -128,8 +128,6 @@ struct AD_ent # define DT_LNK 2 #endif -extern char *program_name; - struct dirstack_state { /* The name of the directory (starting with and relative to a command diff --git a/src/rm.c b/src/rm.c index eb90bf2..7304330 100644 --- a/src/rm.c +++ b/src/rm.c @@ -66,9 +66,6 @@ proper_name ("Richard M. Stallman"), \ proper_name ("Jim Meyering") -/* Name this program was run with. */ -char const *program_name; - /* For long options that have no equivalent short option, use a non-character as a pseudo short option, starting with CHAR_MAX + 1. */ enum @@ -236,7 +233,7 @@ main (int argc, char **argv) int c; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/rmdir.c b/src/rmdir.c index 4ed2f77..64575b0 100644 --- a/src/rmdir.c +++ b/src/rmdir.c @@ -38,9 +38,6 @@ #define AUTHORS proper_name ("David MacKenzie") -/* The name this program was run with. */ -char const *program_name; - /* If true, remove empty parent directories. */ static bool remove_empty_parents; @@ -193,7 +190,7 @@ main (int argc, char **argv) int optc; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/runcon.c b/src/runcon.c index 5f9746c..a5c2300 100644 --- a/src/runcon.c +++ b/src/runcon.c @@ -72,9 +72,6 @@ static struct option long_options[] = { {NULL, 0, NULL, 0} }; -/* The name the program was run with. */ -char const *program_name; - void usage (int status) { @@ -122,7 +119,7 @@ main (int argc, char **argv) context_t con; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/seq.c b/src/seq.c index 2fe6ec2..55518df 100644 --- a/src/seq.c +++ b/src/seq.c @@ -43,9 +43,6 @@ /* If true print all number with equal width. */ static bool equal_width; -/* The name that this program was run with. */ -char const *program_name; - /* The string used to separate two numbers. */ static char const *separator; @@ -380,7 +377,7 @@ main (int argc, char **argv) char const *format_str = NULL; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/setuidgid.c b/src/setuidgid.c index a6262fe..e910357 100644 --- a/src/setuidgid.c +++ b/src/setuidgid.c @@ -39,8 +39,6 @@ #define SETUIDGID_FAILURE 111 -char const *program_name; - void usage (int status) { @@ -84,7 +82,7 @@ main (int argc, char **argv) gid_t primary_gid; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/shred.c b/src/shred.c index 1b94181..bfafa96 100644 --- a/src/shred.c +++ b/src/shred.c @@ -148,9 +148,6 @@ static struct option const long_opts[] = {NULL, 0, NULL, 0} }; -/* Global variable for error printing purposes */ -char const *program_name; /* Initialized before any possible use */ - void usage (int status) { @@ -1100,7 +1097,7 @@ main (int argc, char **argv) char const *random_source = NULL; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/shuf.c b/src/shuf.c index 359aeb0..ca5345b 100644 --- a/src/shuf.c +++ b/src/shuf.c @@ -36,9 +36,6 @@ #define AUTHORS proper_name ("Paul Eggert") -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -261,7 +258,7 @@ main (int argc, char **argv) size_t *permutation; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/sleep.c b/src/sleep.c index 5ae7045..4176977 100644 --- a/src/sleep.c +++ b/src/sleep.c @@ -35,9 +35,6 @@ proper_name ("Jim Meyering"), \ proper_name ("Paul Eggert") -/* The name by which this program was run. */ -char const *program_name; - void usage (int status) { @@ -107,7 +104,7 @@ main (int argc, char **argv) bool ok = true; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/sort.c b/src/sort.c index 5b272e7..632c5c8 100644 --- a/src/sort.c +++ b/src/sort.c @@ -183,9 +183,6 @@ struct month int val; }; -/* The name this program was run with. */ -char const *program_name; - /* FIXME: None of these tables work with multibyte character sets. Also, there are many other bugs when handling multibyte characters. One way to fix this is to rewrite `sort' to use wide characters @@ -2757,7 +2754,7 @@ main (int argc, char **argv) char const *outfile = NULL; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/split.c b/src/split.c index 4937e55..71200fb 100644 --- a/src/split.c +++ b/src/split.c @@ -46,9 +46,6 @@ #define DEFAULT_SUFFIX_LENGTH 2 -/* The name this program was run with. */ -char const *program_name; - /* Base name of output files. */ static char const *outbase; @@ -395,7 +392,7 @@ main (int argc, char **argv) int digits_optind = 0; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/stat.c b/src/stat.c index 7b750a0..0d52c27 100644 --- a/src/stat.c +++ b/src/stat.c @@ -173,8 +173,6 @@ static struct option const long_options[] = { {NULL, 0, NULL, 0} }; -char const *program_name; - /* Whether to follow symbolic links; True for --dereference (-L). */ static bool follow_links; @@ -1005,7 +1003,7 @@ main (int argc, char *argv[]) bool ok = true; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/stty.c b/src/stty.c index 3441365..004c318 100644 --- a/src/stty.c +++ b/src/stty.c @@ -455,9 +455,6 @@ static struct option longopts[] = {NULL, 0, NULL, 0} }; -/* The name this program was run with. */ -char const *program_name; - static void wrapf (const char *message, ...) __attribute__ ((__format__ (__printf__, 1, 2))); @@ -745,7 +742,7 @@ main (int argc, char **argv) const char *device_name; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/su.c b/src/su.c index d6aaaaa..f6b61f7 100644 --- a/src/su.c +++ b/src/su.c @@ -128,9 +128,6 @@ extern char **environ; static void run_shell (char const *, char const *, char **, size_t) ATTRIBUTE_NORETURN; -/* The name this program was run with. */ -char const *program_name; - /* If true, pass the `-f' option to the subshell. */ static bool fast_startup; @@ -414,7 +411,7 @@ main (int argc, char **argv) struct passwd pw_copy; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/sum.c b/src/sum.c index a2aa945..4dfc867 100644 --- a/src/sum.c +++ b/src/sum.c @@ -36,9 +36,6 @@ proper_name ("Kayvan Aghaiepour"), \ proper_name ("David MacKenzie") -/* The name this program was run with. */ -char const *program_name; - /* True if any of the files read were the standard input. */ static bool have_read_stdin; @@ -228,7 +225,7 @@ main (int argc, char **argv) bool (*sum_func) (const char *, int) = bsd_sum_file; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/sync.c b/src/sync.c index fe09c01..96dcf09 100644 --- a/src/sync.c +++ b/src/sync.c @@ -30,9 +30,6 @@ #define AUTHORS proper_name ("Jim Meyering") -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -57,7 +54,7 @@ int main (int argc, char **argv) { initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/system.h b/src/system.h index f7c689f..c69ddca 100644 --- a/src/system.h +++ b/src/system.h @@ -462,6 +462,8 @@ enum of the 100 binaries. */ #define proper_name(x) (x) +#include "progname.h" + #define case_GETOPT_VERSION_CHAR(Program_name, Authors) \ case GETOPT_VERSION_CHAR: \ version_etc (stdout, Program_name, PACKAGE_NAME, VERSION, Authors, \ diff --git a/src/tac.c b/src/tac.c index baaf5ed..9cf6d60 100644 --- a/src/tac.c +++ b/src/tac.c @@ -75,9 +75,6 @@ tac -r -s '.\| /* The number of bytes per atomic write. */ #define WRITESIZE 8192 -/* The name this program was run with. */ -char const *program_name; - /* The string that separates the records of the file. */ static char const *separator; @@ -575,7 +572,7 @@ main (int argc, char **argv) char const *const *file; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/tail.c b/src/tail.c index f6ade24..1ce207e 100644 --- a/src/tail.c +++ b/src/tail.c @@ -162,9 +162,6 @@ enum header_mode static uintmax_t max_n_unchanged_stats_between_opens = DEFAULT_MAX_N_UNCHANGED_STATS_BETWEEN_OPENS; -/* The name this program was run with. */ -char const *program_name; - /* The process ID of the process (presumably on the current host) that is writing to all followed files. */ static pid_t pid; @@ -1599,7 +1596,7 @@ main (int argc, char **argv) double sleep_interval = 1.0; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/tee.c b/src/tee.c index 2f1c7bb..162455c 100644 --- a/src/tee.c +++ b/src/tee.c @@ -41,9 +41,6 @@ static bool append; /* If true, ignore interrupts. */ static bool ignore_interrupts; -/* The name that this program was run with. */ -char const *program_name; - static struct option const long_options[] = { {"append", no_argument, NULL, 'a'}, @@ -86,7 +83,7 @@ main (int argc, char **argv) int optc; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/test.c b/src/test.c index 88579d2..858a837 100644 --- a/src/test.c +++ b/src/test.c @@ -48,8 +48,6 @@ # include #endif -char const *program_name; - /* Exit status for syntax errors, etc. */ enum { TEST_TRUE, TEST_FALSE, TEST_FAILURE }; @@ -809,7 +807,7 @@ main (int margc, char **margv) return (test_error_return); #else /* TEST_STANDALONE */ initialize_main (&margc, &margv); - program_name = margv[0]; + set_program_name (margv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/timeout.c b/src/timeout.c index 9373cfa..f7f9af0 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -83,8 +83,6 @@ static int term_signal = SIGTERM; /* same default as kill command. */ static int monitored_pid; static int sigs_to_ignore[NSIG]; /* so monitor can ignore sigs it resends. */ -char const *program_name; - static struct option const long_options[] = { {"signal", required_argument, NULL, 's'}, {NULL, 0, NULL, 0} @@ -224,7 +222,7 @@ main (int argc, char **argv) char *ep; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/touch.c b/src/touch.c index b8e4f2e..bbc9c60 100644 --- a/src/touch.c +++ b/src/touch.c @@ -48,9 +48,6 @@ #define CH_ATIME 1 #define CH_MTIME 2 -/* The name by which this program was run. */ -char const *program_name; - /* Which timestamps to change. */ static int change_times; @@ -280,7 +277,7 @@ main (int argc, char **argv) char const *flex_date = NULL; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/tr.c b/src/tr.c index 532e4f0..e1bb404 100644 --- a/src/tr.c +++ b/src/tr.c @@ -193,9 +193,6 @@ es_match (struct E_string const *es, size_t i, char c) return es->s[i] == c && !es->escaped[i]; } -/* The name by which this program was run. */ -char const *program_name; - /* When true, each sequence in the input of a repeated character (call it c) is replaced (in the output) by a single occurrence of c for every c in the squeeze set. */ @@ -1671,7 +1668,7 @@ main (int argc, char **argv) struct Spec_list *s2 = &buf2; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/true.c b/src/true.c index ae6990a..75e53bc 100644 --- a/src/true.c +++ b/src/true.c @@ -32,9 +32,6 @@ #define AUTHORS proper_name ("Jim Meyering") -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -58,7 +55,7 @@ int main (int argc, char **argv) { initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/tsort.c b/src/tsort.c index a68ba04..703b855 100644 --- a/src/tsort.c +++ b/src/tsort.c @@ -59,9 +59,6 @@ struct item struct successor *top; }; -/* The name this program was run with. */ -char const *program_name; - /* The head of the sorted list. */ static struct item *head = NULL; @@ -534,7 +531,7 @@ main (int argc, char **argv) bool ok; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/tty.c b/src/tty.c index fe19b01..c7b13dc 100644 --- a/src/tty.c +++ b/src/tty.c @@ -42,9 +42,6 @@ enum #define AUTHORS proper_name ("David MacKenzie") -/* The name under which this program was run. */ -char const *program_name; - /* If true, return an exit status but produce no output. */ static bool silent; @@ -85,7 +82,7 @@ main (int argc, char **argv) int optc; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/uname.c b/src/uname.c index 4691afc..3870dfa 100644 --- a/src/uname.c +++ b/src/uname.c @@ -86,9 +86,6 @@ /* Operating system. */ #define PRINT_OPERATING_SYSTEM 128 -/* The name this program was run with, for error messages. */ -char const *program_name; - static struct option const uname_long_options[] = { {"all", no_argument, NULL, 'a'}, @@ -269,7 +266,7 @@ main (int argc, char **argv) unsigned int toprint = 0; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/unexpand.c b/src/unexpand.c index 1fc65d3..5a2d0cd 100644 --- a/src/unexpand.c +++ b/src/unexpand.c @@ -52,9 +52,6 @@ allocated for the output line. */ #define OUTPUT_BLOCK 256 -/* The name this program was run with. */ -char const *program_name; - /* If true, convert blanks even after nonblank characters have been read on the line. */ static bool convert_entire_line; @@ -464,7 +461,7 @@ main (int argc, char **argv) bool convert_first_only = false; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/uniq.c b/src/uniq.c index f8948e2..5af5271 100644 --- a/src/uniq.c +++ b/src/uniq.c @@ -50,9 +50,6 @@ } \ while (0) -/* The name this program was run with. */ -char const *program_name; - /* True if the LC_COLLATE locale is hard. */ static bool hard_LC_COLLATE; @@ -418,7 +415,7 @@ main (int argc, char **argv) file[0] = file[1] = "-"; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/unlink.c b/src/unlink.c index 0ef2448..36595c8 100644 --- a/src/unlink.c +++ b/src/unlink.c @@ -35,9 +35,6 @@ #define AUTHORS proper_name ("Michael Stone") -/* Name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -62,7 +59,7 @@ int main (int argc, char **argv) { initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/uptime.c b/src/uptime.c index 1179ce5..9e3384f 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -47,9 +47,6 @@ int getloadavg (); -/* The name this program was run with. */ -char const *program_name; - static void print_uptime (size_t n, const STRUCT_UTMP *this) { @@ -216,7 +213,7 @@ int main (int argc, char **argv) { initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/users.c b/src/users.c index b1e8b3d..551616e 100644 --- a/src/users.c +++ b/src/users.c @@ -35,9 +35,6 @@ proper_name ("Joseph Arceneaux"), \ proper_name ("David MacKenzie") -/* The name this program was run with. */ -char const *program_name; - static int userid_compare (const void *v_a, const void *v_b) { @@ -124,7 +121,7 @@ int main (int argc, char **argv) { initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/wc.c b/src/wc.c index 731eb4a..8073bb0 100644 --- a/src/wc.c +++ b/src/wc.c @@ -49,9 +49,6 @@ /* Size of atomic reads. */ #define BUFFER_SIZE (16 * 1024) -/* The name this program was run with. */ -char const *program_name; - /* Cumulative number of lines, words, chars and bytes in all files so far. max_line_length is the maximum over all files processed so far. */ static uintmax_t total_lines; @@ -589,7 +586,7 @@ main (int argc, char **argv) struct Tokens tok; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/who.c b/src/who.c index bec924f..34b5648 100644 --- a/src/who.c +++ b/src/who.c @@ -98,9 +98,6 @@ char *ttyname (); -/* The name this program was run with. */ -char const *program_name; - /* If true, attempt to canonicalize hostnames via a DNS lookup. */ static bool do_lookup; @@ -677,7 +674,7 @@ main (int argc, char **argv) bool assumptions = true; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/whoami.c b/src/whoami.c index 7686fd0..c3b709b 100644 --- a/src/whoami.c +++ b/src/whoami.c @@ -35,9 +35,6 @@ #define AUTHORS proper_name ("Richard Mlynarik") -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -66,7 +63,7 @@ main (int argc, char **argv) uid_t uid; initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); diff --git a/src/yes.c b/src/yes.c index 7dec1ec..d72c5da 100644 --- a/src/yes.c +++ b/src/yes.c @@ -31,9 +31,6 @@ #define AUTHORS proper_name ("David MacKenzie") -/* The name this program was run with. */ -char const *program_name; - void usage (int status) { @@ -63,7 +60,7 @@ int main (int argc, char **argv) { initialize_main (&argc, &argv); - program_name = argv[0]; + set_program_name (argv[0]); setlocale (LC_ALL, ""); bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); -- 2.7.4