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-w32-bcfeb2ac44a468f7f7487883f418e026f8e76348.tar.gz busybox-w32-bcfeb2ac44a468f7f7487883f418e026f8e76348.tar.bz2 busybox-w32-bcfeb2ac44a468f7f7487883f418e026f8e76348.zip |
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[] = { | |||
60 | }; | 60 | }; |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | //#include <sys/types.h> | ||
64 | //#include <sys/wait.h> | ||
65 | //#include <signal.h> | ||
66 | #include <stdlib.h> | 63 | #include <stdlib.h> |
67 | #include <string.h> | 64 | #include <string.h> |
68 | #include <unistd.h> | 65 | #include <unistd.h> |
@@ -93,37 +90,42 @@ extern int gunzip_main(int argc, char **argv) | |||
93 | 90 | ||
94 | /* if called as zcat */ | 91 | /* if called as zcat */ |
95 | if (strcmp(applet_name, "zcat") == 0) { | 92 | if (strcmp(applet_name, "zcat") == 0) { |
96 | if (argc != 2) { | 93 | if (argc > 2) { |
97 | show_usage(); | 94 | show_usage(); |
98 | } | 95 | } |
99 | optind = 1; | 96 | else if (argc == 2) { |
100 | flags |= (gunzip_force | gunzip_to_stdout); | 97 | /* a filename was specified */ |
98 | flags |= (gunzip_to_stdout | gunzip_force); | ||
99 | optind = 1; | ||
100 | } else { | ||
101 | /* read from stdin, this gets caught below as argv[optind] will be NULL */ | ||
102 | optind = argc; | ||
103 | } | ||
101 | } else { | 104 | } else { |
102 | /* workout flags as regular gunzip */ | 105 | /* workout flags as regular gunzip */ |
103 | /* set default flags */ | 106 | while ((opt = getopt(argc, argv, "ctfh")) != -1) { |
104 | if (argc == 1) { | 107 | switch (opt) { |
105 | flags |= (gunzip_from_stdin | gunzip_to_stdout); | 108 | case 'c': |
106 | } else { | 109 | flags |= gunzip_to_stdout; |
107 | /* Parse any options */ | 110 | break; |
108 | while ((opt = getopt(argc, argv, "ctfh")) != -1) { | 111 | case 'f': |
109 | switch (opt) { | 112 | flags |= gunzip_force; |
110 | case 'c': | 113 | break; |
111 | flags |= gunzip_to_stdout; | 114 | case 't': |
112 | break; | 115 | flags |= gunzip_test; |
113 | case 'f': | 116 | break; |
114 | flags |= gunzip_force; | 117 | case 'h': |
115 | break; | 118 | default: |
116 | case 't': | 119 | show_usage(); /* exit's inside usage */ |
117 | flags |= gunzip_test; | ||
118 | break; | ||
119 | case 'h': | ||
120 | default: | ||
121 | show_usage(); /* exit's inside usage */ | ||
122 | } | ||
123 | } | 120 | } |
124 | } | 121 | } |
125 | } | 122 | } |
126 | 123 | ||
124 | /* no filename specified so it must be reading from stdin to stdout */ | ||
125 | if (argv[optind] == NULL) { | ||
126 | flags |= (gunzip_from_stdin |gunzip_to_stdout |gunzip_force); | ||
127 | } | ||
128 | |||
127 | /* Set input filename and number */ | 129 | /* Set input filename and number */ |
128 | if (flags & gunzip_from_stdin) { | 130 | if (flags & gunzip_from_stdin) { |
129 | in_file = stdin; | 131 | in_file = stdin; |
@@ -60,9 +60,6 @@ static char *license_msg[] = { | |||
60 | }; | 60 | }; |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | //#include <sys/types.h> | ||
64 | //#include <sys/wait.h> | ||
65 | //#include <signal.h> | ||
66 | #include <stdlib.h> | 63 | #include <stdlib.h> |
67 | #include <string.h> | 64 | #include <string.h> |
68 | #include <unistd.h> | 65 | #include <unistd.h> |
@@ -93,37 +90,42 @@ extern int gunzip_main(int argc, char **argv) | |||
93 | 90 | ||
94 | /* if called as zcat */ | 91 | /* if called as zcat */ |
95 | if (strcmp(applet_name, "zcat") == 0) { | 92 | if (strcmp(applet_name, "zcat") == 0) { |
96 | if (argc != 2) { | 93 | if (argc > 2) { |
97 | show_usage(); | 94 | show_usage(); |
98 | } | 95 | } |
99 | optind = 1; | 96 | else if (argc == 2) { |
100 | flags |= (gunzip_force | gunzip_to_stdout); | 97 | /* a filename was specified */ |
98 | flags |= (gunzip_to_stdout | gunzip_force); | ||
99 | optind = 1; | ||
100 | } else { | ||
101 | /* read from stdin, this gets caught below as argv[optind] will be NULL */ | ||
102 | optind = argc; | ||
103 | } | ||
101 | } else { | 104 | } else { |
102 | /* workout flags as regular gunzip */ | 105 | /* workout flags as regular gunzip */ |
103 | /* set default flags */ | 106 | while ((opt = getopt(argc, argv, "ctfh")) != -1) { |
104 | if (argc == 1) { | 107 | switch (opt) { |
105 | flags |= (gunzip_from_stdin | gunzip_to_stdout); | 108 | case 'c': |
106 | } else { | 109 | flags |= gunzip_to_stdout; |
107 | /* Parse any options */ | 110 | break; |
108 | while ((opt = getopt(argc, argv, "ctfh")) != -1) { | 111 | case 'f': |
109 | switch (opt) { | 112 | flags |= gunzip_force; |
110 | case 'c': | 113 | break; |
111 | flags |= gunzip_to_stdout; | 114 | case 't': |
112 | break; | 115 | flags |= gunzip_test; |
113 | case 'f': | 116 | break; |
114 | flags |= gunzip_force; | 117 | case 'h': |
115 | break; | 118 | default: |
116 | case 't': | 119 | show_usage(); /* exit's inside usage */ |
117 | flags |= gunzip_test; | ||
118 | break; | ||
119 | case 'h': | ||
120 | default: | ||
121 | show_usage(); /* exit's inside usage */ | ||
122 | } | ||
123 | } | 120 | } |
124 | } | 121 | } |
125 | } | 122 | } |
126 | 123 | ||
124 | /* no filename specified so it must be reading from stdin to stdout */ | ||
125 | if (argv[optind] == NULL) { | ||
126 | flags |= (gunzip_from_stdin |gunzip_to_stdout |gunzip_force); | ||
127 | } | ||
128 | |||
127 | /* Set input filename and number */ | 129 | /* Set input filename and number */ |
128 | if (flags & gunzip_from_stdin) { | 130 | if (flags & gunzip_from_stdin) { |
129 | in_file = stdin; | 131 | in_file = stdin; |