dj(1), mm(1), npc(1), scrut(1), str(1): consistent argv[0] handling

This commit is contained in:
2024-07-20 07:18:59 -06:00
parent f96ed9c1f3
commit 0282b60e65
5 changed files with 29 additions and 22 deletions

View File

@@ -30,7 +30,7 @@
extern int errno;
char *program_name = "dj";
static char *program_name = "dj";
/* dj uses two structures that respectively correspond to the reading and
* writing ends of its jockeyed "pipe". User-configurable members are noted
@@ -150,7 +150,7 @@ usage(char *s) {
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", program_name
"\t[-o file] [-B block_size] [-S offset]\n", s
);
return EX_USAGE;
@@ -163,6 +163,7 @@ int main(int argc, char *argv[]) {
size_t i; /* side of io being modified */
char noerror; /* 0=exits (default) 1=retries on partial reads or writes */
struct Io io[2 /* { in, out } */];
char *s = (argv[0] == NULL ? program_name : argv[0]);
/* Set defaults. */
align = -1;
@@ -233,7 +234,7 @@ int main(int argc, char *argv[]) {
/* FALLTHROUGH */
default:
return usage(program_name);
return usage(s);
}
}
}
@@ -241,7 +242,7 @@ int main(int argc, char *argv[]) {
assert(io->fd != STDIN_FILENO || io->fl == read_flags);
assert(io->fd != STDOUT_FILENO || io->fl == write_flags);
if (argc > optind) { return usage(program_name); }
if (argc > optind) { return usage(s); }
for (i = 0; i < (sizeof io) / (sizeof *io); ++i) {
/* buffer allocation */