diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-18 13:34:09 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-18 13:34:09 +0000 |
commit | bcfeb2ac44a468f7f7487883f418e026f8e76348 (patch) | |
tree | dbc3934a4d88ad99d6563a32778a0f276739dfa4 | |
parent | 2771d1a574dbf940cc7d03a04ed1ae0f6d97d3c2 (diff) | |
download | busybox-bcfeb2ac44a468f7f7487883f418e026f8e76348.tar.gz |
Fix zcat/gunzip when reading from stdin
-rw-r--r-- | archival/gunzip.c | 54 | ||||
-rw-r--r-- | gunzip.c | 54 |
2 files changed, 56 insertions, 52 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c index 246ce2f4e..c3960e953 100644 --- a/archival/gunzip.c +++ b/archival/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,37 +90,42 @@ 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(); } - optind = 1; - flags |= (gunzip_force | gunzip_to_stdout); + else if (argc == 2) { + /* a filename was specified */ + flags |= (gunzip_to_stdout | gunzip_force); + optind = 1; + } 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': - flags |= gunzip_to_stdout; - break; - case 'f': - flags |= gunzip_force; - break; - case 't': - flags |= gunzip_test; - break; - case 'h': - default: - show_usage(); /* exit's inside usage */ - } + while ((opt = getopt(argc, argv, "ctfh")) != -1) { + switch (opt) { + case 'c': + flags |= gunzip_to_stdout; + break; + case 'f': + flags |= gunzip_force; + break; + case 't': + flags |= gunzip_test; + break; + case 'h': + default: + show_usage(); /* exit's inside usage */ } } } + /* 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 */ if (flags & gunzip_from_stdin) { in_file = stdin; @@ -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,37 +90,42 @@ 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(); } - optind = 1; - flags |= (gunzip_force | gunzip_to_stdout); + else if (argc == 2) { + /* a filename was specified */ + flags |= (gunzip_to_stdout | gunzip_force); + optind = 1; + } 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': - flags |= gunzip_to_stdout; - break; - case 'f': - flags |= gunzip_force; - break; - case 't': - flags |= gunzip_test; - break; - case 'h': - default: - show_usage(); /* exit's inside usage */ - } + while ((opt = getopt(argc, argv, "ctfh")) != -1) { + switch (opt) { + case 'c': + flags |= gunzip_to_stdout; + break; + case 'f': + flags |= gunzip_force; + break; + case 't': + flags |= gunzip_test; + break; + case 'h': + default: + show_usage(); /* exit's inside usage */ } } } + /* 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 */ if (flags & gunzip_from_stdin) { in_file = stdin; |