aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2004-01-05 12:35:05 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2004-01-05 12:35:05 +0000
commitab7780655b9e787cca783ebd13cf8f2ded0fe0e3 (patch)
treed5bd470a148cf464520db73a2e8835623fa59233
parent6cb3bc056c5bf49e6b0910a2437b908777bef139 (diff)
downloadbusybox-w32-ab7780655b9e787cca783ebd13cf8f2ded0fe0e3.tar.gz
busybox-w32-ab7780655b9e787cca783ebd13cf8f2ded0fe0e3.tar.bz2
busybox-w32-ab7780655b9e787cca783ebd13cf8f2ded0fe0e3.zip
Use bb_getopt_ulflags, save 150 bytes.
-rw-r--r--archival/gunzip.c39
1 files changed, 11 insertions, 28 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c
index f229ae524..367e0470c 100644
--- a/archival/gunzip.c
+++ b/archival/gunzip.c
@@ -71,37 +71,20 @@ static char *license_msg[] = {
71#include "busybox.h" 71#include "busybox.h"
72#include "unarchive.h" 72#include "unarchive.h"
73 73
74const char gunzip_to_stdout = 1; 74#define GUNZIP_OPT_STDOUT 1
75const char gunzip_force = 2; 75#define GUNZIP_OPT_FORCE 2
76const char gunzip_test = 4; 76#define GUNZIP_OPT_TEST 4
77#define GUNZIP_OPT_DECOMPRESS 8
77 78
78extern int gunzip_main(int argc, char **argv) 79extern int gunzip_main(int argc, char **argv)
79{ 80{
80 char status = EXIT_SUCCESS; 81 char status = EXIT_SUCCESS;
81 char flags = 0; 82 unsigned long opt;
82 int opt;
83 83
84 opt = bb_getopt_ulflags(argc, argv, "cftd");
84 /* if called as zcat */ 85 /* if called as zcat */
85 if (strcmp(bb_applet_name, "zcat") == 0) { 86 if (strcmp(bb_applet_name, "zcat") == 0) {
86 flags |= gunzip_to_stdout; 87 opt |= GUNZIP_OPT_STDOUT;
87 }
88
89 while ((opt = getopt(argc, argv, "ctfhd")) != -1) {
90 switch (opt) {
91 case 'c':
92 flags |= gunzip_to_stdout;
93 break;
94 case 'f':
95 flags |= gunzip_force;
96 break;
97 case 't':
98 flags |= gunzip_test;
99 break;
100 case 'd': /* Used to convert gzip to gunzip. */
101 break;
102 default:
103 bb_show_usage(); /* exit's inside usage */
104 }
105 } 88 }
106 89
107 do { 90 do {
@@ -116,7 +99,7 @@ extern int gunzip_main(int argc, char **argv)
116 99
117 if (old_path == NULL || strcmp(old_path, "-") == 0) { 100 if (old_path == NULL || strcmp(old_path, "-") == 0) {
118 src_fd = fileno(stdin); 101 src_fd = fileno(stdin);
119 flags |= gunzip_to_stdout; 102 opt |= GUNZIP_OPT_STDOUT;
120 } else { 103 } else {
121 src_fd = bb_xopen(old_path, O_RDONLY); 104 src_fd = bb_xopen(old_path, O_RDONLY);
122 105
@@ -127,15 +110,15 @@ extern int gunzip_main(int argc, char **argv)
127 } 110 }
128 111
129 /* Check that the input is sane. */ 112 /* Check that the input is sane. */
130 if (isatty(src_fd) && ((flags & gunzip_force) == 0)) { 113 if (isatty(src_fd) && ((opt & GUNZIP_OPT_FORCE) == 0)) {
131 bb_error_msg_and_die 114 bb_error_msg_and_die
132 ("compressed data not read from terminal. Use -f to force it."); 115 ("compressed data not read from terminal. Use -f to force it.");
133 } 116 }
134 117
135 /* Set output filename and number */ 118 /* Set output filename and number */
136 if (flags & gunzip_test) { 119 if (opt & GUNZIP_OPT_TEST) {
137 dst_fd = bb_xopen("/dev/null", O_WRONLY); /* why does test use filenum 2 ? */ 120 dst_fd = bb_xopen("/dev/null", O_WRONLY); /* why does test use filenum 2 ? */
138 } else if (flags & gunzip_to_stdout) { 121 } else if (opt & GUNZIP_OPT_STDOUT) {
139 dst_fd = fileno(stdout); 122 dst_fd = fileno(stdout);
140 } else { 123 } else {
141 char *extension; 124 char *extension;