diff --git a/src/dj.c b/src/dj.c index 1913dd9..c4ebf38 100644 --- a/src/dj.c +++ b/src/dj.c @@ -146,11 +146,13 @@ parse(char *s) { } static int -usage(char *s) { - fprintf( - stderr, "Usage: %s [-Hn] [-a byte] [-c count]\n" +usage(char *argv0) { + (void)fprintf( + stderr, + "Usage: %s [-Hn] [-a byte] [-c count]\n" "\t[-i file] [-b block_size] [-s offset]\n" - "\t[-o file] [-B block_size] [-S offset]\n", s + "\t[-o file] [-B block_size] [-S offset]\n", + argv0 ); return EX_USAGE; diff --git a/src/intcmp.c b/src/intcmp.c index f990a10..35fecf3 100644 --- a/src/intcmp.c +++ b/src/intcmp.c @@ -32,8 +32,9 @@ char *program_name = "intcmp"; -int usage(char *s) { - fprintf(stderr, "Usage: %s [-egl] integer integer...\n", s); +static int +usage(char *argv0) { + (void)fprintf(stderr, "Usage: %s [-egl] integer integer...\n", argv0); return EX_USAGE; } diff --git a/src/mm.c b/src/mm.c index 1d97ab5..d148446 100644 --- a/src/mm.c +++ b/src/mm.c @@ -107,11 +107,13 @@ oserr(char *s, char *r) { } \ return retval -/* Prints a usage text, in which s is the program being run (i.e. argv[0]), and - * returns an exit status appropriate for a usage error. */ -int usage(char *s) { - - fprintf(stderr, "Usage: %s [-aenu] [-i input]... [-o output]...\n", s); +static int +usage(char *argv0) { + (void)fprintf( + stderr, + "Usage: %s [-aenu] [-i input]... [-o output]...\n", + argv0 + ); return EX_USAGE; } diff --git a/src/npc.c b/src/npc.c index 4f74c6f..4cc4160 100644 --- a/src/npc.c +++ b/src/npc.c @@ -25,8 +25,10 @@ char *program_name = "npc"; -int usage(char *s) { - fprintf(stderr, "Usage: %s [-et]\n", s); +static int +usage(char *argv0) { + fprintf(stderr, "Usage: %s [-et]\n", argv0); + return EX_USAGE; } diff --git a/src/scrut.c b/src/scrut.c index 7320c8f..4d5a932 100644 --- a/src/scrut.c +++ b/src/scrut.c @@ -27,15 +27,18 @@ * S_ISUID, S_ISVTX */ char *program_name = "scrut"; -static char args[] = "bcdefgkprsuwxLS"; +#define OPTS "bcdefgkprsuwxLS" +static char *opts = OPTS; + +static int +usage(char *argv0) { + (void)fprintf(stderr, "Usage: %s [-" OPTS "] file...\n", argv0); -int usage(char *s) { - fprintf(stderr, "Usage: %s [-%s] file...\n", s, args); return EX_USAGE; } int main(int argc, char *argv[]) { - char sel[(sizeof args) / (sizeof *args)]; + char sel[(sizeof opts) / (sizeof *opts)]; program_name = (argv[0] == NULL ? program_name : argv[0]); if (argc < 2) { return usage(program_name); } @@ -44,9 +47,9 @@ int main(int argc, char *argv[]) { char *p; memset(sel, '\0', sizeof sel); - for (int c; (c = getopt(argc, argv, args)) != -1;) { - if ((p = strchr(args, c)) == NULL) { return usage(program_name); } - else { sel[p - args] = c; } + for (int c; (c = getopt(argc, argv, opts)) != -1;) { + if ((p = strchr(opts, c)) == NULL) { return usage(program_name); } + else { sel[p - opts] = c; } } /* straighten out selections; permute out nulls */ diff --git a/src/str.c b/src/str.c index e503470..a41e4a1 100644 --- a/src/str.c +++ b/src/str.c @@ -45,8 +45,10 @@ static struct { { NULL, NULL } /* marks end */ }; -int usage(char *s){ - fprintf(stderr, "Usage: %s type string...\n", s); +static int +usage(char *argv0){ + (void)fprintf(stderr, "Usage: %s type string...\n", argv0); + return EX_USAGE; }