Fix zcat/gunzip when reading from stdin
This commit is contained in:
parent
2771d1a574
commit
bcfeb2ac44
@ -60,9 +60,6 @@ static char *license_msg[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
//#include <sys/types.h>
|
||||
//#include <sys/wait.h>
|
||||
//#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -93,18 +90,19 @@ extern int gunzip_main(int argc, char **argv)
|
||||
|
||||
/* if called as zcat */
|
||||
if (strcmp(applet_name, "zcat") == 0) {
|
||||
if (argc != 2) {
|
||||
if (argc > 2) {
|
||||
show_usage();
|
||||
}
|
||||
else if (argc == 2) {
|
||||
/* a filename was specified */
|
||||
flags |= (gunzip_to_stdout | gunzip_force);
|
||||
optind = 1;
|
||||
flags |= (gunzip_force | gunzip_to_stdout);
|
||||
} else {
|
||||
/* read from stdin, this gets caught below as argv[optind] will be NULL */
|
||||
optind = argc;
|
||||
}
|
||||
} else {
|
||||
/* workout flags as regular gunzip */
|
||||
/* set default flags */
|
||||
if (argc == 1) {
|
||||
flags |= (gunzip_from_stdin | gunzip_to_stdout);
|
||||
} else {
|
||||
/* Parse any options */
|
||||
while ((opt = getopt(argc, argv, "ctfh")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
@ -122,6 +120,10 @@ extern int gunzip_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no filename specified so it must be reading from stdin to stdout */
|
||||
if (argv[optind] == NULL) {
|
||||
flags |= (gunzip_from_stdin |gunzip_to_stdout |gunzip_force);
|
||||
}
|
||||
|
||||
/* Set input filename and number */
|
||||
|
22
gunzip.c
22
gunzip.c
@ -60,9 +60,6 @@ static char *license_msg[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
//#include <sys/types.h>
|
||||
//#include <sys/wait.h>
|
||||
//#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
@ -93,18 +90,19 @@ extern int gunzip_main(int argc, char **argv)
|
||||
|
||||
/* if called as zcat */
|
||||
if (strcmp(applet_name, "zcat") == 0) {
|
||||
if (argc != 2) {
|
||||
if (argc > 2) {
|
||||
show_usage();
|
||||
}
|
||||
else if (argc == 2) {
|
||||
/* a filename was specified */
|
||||
flags |= (gunzip_to_stdout | gunzip_force);
|
||||
optind = 1;
|
||||
flags |= (gunzip_force | gunzip_to_stdout);
|
||||
} else {
|
||||
/* read from stdin, this gets caught below as argv[optind] will be NULL */
|
||||
optind = argc;
|
||||
}
|
||||
} else {
|
||||
/* workout flags as regular gunzip */
|
||||
/* set default flags */
|
||||
if (argc == 1) {
|
||||
flags |= (gunzip_from_stdin | gunzip_to_stdout);
|
||||
} else {
|
||||
/* Parse any options */
|
||||
while ((opt = getopt(argc, argv, "ctfh")) != -1) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
@ -122,6 +120,10 @@ extern int gunzip_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no filename specified so it must be reading from stdin to stdout */
|
||||
if (argv[optind] == NULL) {
|
||||
flags |= (gunzip_from_stdin |gunzip_to_stdout |gunzip_force);
|
||||
}
|
||||
|
||||
/* Set input filename and number */
|
||||
|
Loading…
Reference in New Issue
Block a user