mirror of
https://github.com/sheumann/hush.git
synced 2025-02-09 17:30:36 +00:00
Eliminate spurious warning, convert to getopt, and eliminate redundant check.
This commit is contained in:
parent
96dcd19b8a
commit
53265546a6
@ -91,7 +91,7 @@ extern int gunzip_main(int argc, char **argv)
|
|||||||
if (strcmp(applet_name, "zcat") == 0)
|
if (strcmp(applet_name, "zcat") == 0)
|
||||||
flags |= gunzip_to_stdout;
|
flags |= gunzip_to_stdout;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "ctfh")) != -1) {
|
while ((opt = getopt(argc, argv, "ctfhd")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'c':
|
case 'c':
|
||||||
flags |= gunzip_to_stdout;
|
flags |= gunzip_to_stdout;
|
||||||
@ -102,6 +102,8 @@ extern int gunzip_main(int argc, char **argv)
|
|||||||
case 't':
|
case 't':
|
||||||
flags |= gunzip_test;
|
flags |= gunzip_test;
|
||||||
break;
|
break;
|
||||||
|
case 'd': /* Used to convert gzip to gunzip. */
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
show_usage(); /* exit's inside usage */
|
show_usage(); /* exit's inside usage */
|
||||||
|
@ -1900,42 +1900,36 @@ int gzip_main(int argc, char **argv)
|
|||||||
int tostdout = 0;
|
int tostdout = 0;
|
||||||
int fromstdin = 0;
|
int fromstdin = 0;
|
||||||
int force = 0;
|
int force = 0;
|
||||||
|
int opt;
|
||||||
|
|
||||||
/* Parse any options */
|
while ((opt = getopt(argc, argv, "cf123456789d")) != -1) {
|
||||||
while (--argc > 0 && **(++argv) == '-') {
|
switch (opt) {
|
||||||
if (*((*argv) + 1) == '\0') {
|
case 'c':
|
||||||
tostdout = 1;
|
tostdout = 1;
|
||||||
}
|
break;
|
||||||
while (*(++(*argv))) {
|
case 'f':
|
||||||
switch (**argv) {
|
force = 1;
|
||||||
case 'c':
|
break;
|
||||||
tostdout = 1;
|
/* Ignore 1-9 (compression level) options */
|
||||||
break;
|
case '1': case '2': case '3': case '4': case '5':
|
||||||
case 'f':
|
case '6': case '7': case '8': case '9':
|
||||||
force = 1;
|
break;
|
||||||
break;
|
|
||||||
/* Ignore 1-9 (compression level) options */
|
|
||||||
case '1': case '2': case '3': case '4': case '5':
|
|
||||||
case '6': case '7': case '8': case '9':
|
|
||||||
break;
|
|
||||||
#ifdef BB_GUNZIP
|
#ifdef BB_GUNZIP
|
||||||
case 'd':
|
case 'd':
|
||||||
exit(gunzip_main(argc, argv));
|
optind = 1;
|
||||||
|
return gunzip_main(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
show_usage();
|
show_usage();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (argc <= 0 ) {
|
if (optind == argc) {
|
||||||
fromstdin = 1;
|
fromstdin = 1;
|
||||||
tostdout = 1;
|
tostdout = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isatty(fileno(stdin)) && fromstdin==1 && force==0)
|
|
||||||
error_msg_and_die( "data not read from terminal. Use -f to force it.");
|
|
||||||
if (isatty(fileno(stdout)) && tostdout==1 && force==0)
|
if (isatty(fileno(stdout)) && tostdout==1 && force==0)
|
||||||
error_msg_and_die( "data not written to terminal. Use -f to force it.");
|
error_msg_and_die( "compressed data not written to terminal. Use -f to force it.");
|
||||||
|
|
||||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||||
if (foreground) {
|
if (foreground) {
|
||||||
@ -1975,9 +1969,7 @@ int gzip_main(int argc, char **argv)
|
|||||||
ifile_size = -1L; /* convention for unknown size */
|
ifile_size = -1L; /* convention for unknown size */
|
||||||
} else {
|
} else {
|
||||||
/* Open up the input file */
|
/* Open up the input file */
|
||||||
if (argc <= 0)
|
strncpy(ifname, argv[optind], MAX_PATH_LEN);
|
||||||
show_usage();
|
|
||||||
strncpy(ifname, *argv, MAX_PATH_LEN);
|
|
||||||
|
|
||||||
/* Open input file */
|
/* Open input file */
|
||||||
inFileNum = open(ifname, O_RDONLY);
|
inFileNum = open(ifname, O_RDONLY);
|
||||||
|
4
gunzip.c
4
gunzip.c
@ -91,7 +91,7 @@ extern int gunzip_main(int argc, char **argv)
|
|||||||
if (strcmp(applet_name, "zcat") == 0)
|
if (strcmp(applet_name, "zcat") == 0)
|
||||||
flags |= gunzip_to_stdout;
|
flags |= gunzip_to_stdout;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "ctfh")) != -1) {
|
while ((opt = getopt(argc, argv, "ctfhd")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'c':
|
case 'c':
|
||||||
flags |= gunzip_to_stdout;
|
flags |= gunzip_to_stdout;
|
||||||
@ -102,6 +102,8 @@ extern int gunzip_main(int argc, char **argv)
|
|||||||
case 't':
|
case 't':
|
||||||
flags |= gunzip_test;
|
flags |= gunzip_test;
|
||||||
break;
|
break;
|
||||||
|
case 'd': /* Used to convert gzip to gunzip. */
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
show_usage(); /* exit's inside usage */
|
show_usage(); /* exit's inside usage */
|
||||||
|
48
gzip.c
48
gzip.c
@ -1900,42 +1900,36 @@ int gzip_main(int argc, char **argv)
|
|||||||
int tostdout = 0;
|
int tostdout = 0;
|
||||||
int fromstdin = 0;
|
int fromstdin = 0;
|
||||||
int force = 0;
|
int force = 0;
|
||||||
|
int opt;
|
||||||
|
|
||||||
/* Parse any options */
|
while ((opt = getopt(argc, argv, "cf123456789d")) != -1) {
|
||||||
while (--argc > 0 && **(++argv) == '-') {
|
switch (opt) {
|
||||||
if (*((*argv) + 1) == '\0') {
|
case 'c':
|
||||||
tostdout = 1;
|
tostdout = 1;
|
||||||
}
|
break;
|
||||||
while (*(++(*argv))) {
|
case 'f':
|
||||||
switch (**argv) {
|
force = 1;
|
||||||
case 'c':
|
break;
|
||||||
tostdout = 1;
|
/* Ignore 1-9 (compression level) options */
|
||||||
break;
|
case '1': case '2': case '3': case '4': case '5':
|
||||||
case 'f':
|
case '6': case '7': case '8': case '9':
|
||||||
force = 1;
|
break;
|
||||||
break;
|
|
||||||
/* Ignore 1-9 (compression level) options */
|
|
||||||
case '1': case '2': case '3': case '4': case '5':
|
|
||||||
case '6': case '7': case '8': case '9':
|
|
||||||
break;
|
|
||||||
#ifdef BB_GUNZIP
|
#ifdef BB_GUNZIP
|
||||||
case 'd':
|
case 'd':
|
||||||
exit(gunzip_main(argc, argv));
|
optind = 1;
|
||||||
|
return gunzip_main(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
show_usage();
|
show_usage();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (argc <= 0 ) {
|
if (optind == argc) {
|
||||||
fromstdin = 1;
|
fromstdin = 1;
|
||||||
tostdout = 1;
|
tostdout = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isatty(fileno(stdin)) && fromstdin==1 && force==0)
|
|
||||||
error_msg_and_die( "data not read from terminal. Use -f to force it.");
|
|
||||||
if (isatty(fileno(stdout)) && tostdout==1 && force==0)
|
if (isatty(fileno(stdout)) && tostdout==1 && force==0)
|
||||||
error_msg_and_die( "data not written to terminal. Use -f to force it.");
|
error_msg_and_die( "compressed data not written to terminal. Use -f to force it.");
|
||||||
|
|
||||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||||
if (foreground) {
|
if (foreground) {
|
||||||
@ -1975,9 +1969,7 @@ int gzip_main(int argc, char **argv)
|
|||||||
ifile_size = -1L; /* convention for unknown size */
|
ifile_size = -1L; /* convention for unknown size */
|
||||||
} else {
|
} else {
|
||||||
/* Open up the input file */
|
/* Open up the input file */
|
||||||
if (argc <= 0)
|
strncpy(ifname, argv[optind], MAX_PATH_LEN);
|
||||||
show_usage();
|
|
||||||
strncpy(ifname, *argv, MAX_PATH_LEN);
|
|
||||||
|
|
||||||
/* Open input file */
|
/* Open input file */
|
||||||
inFileNum = open(ifname, O_RDONLY);
|
inFileNum = open(ifname, O_RDONLY);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user