diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2002-08-24 10:30:36 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2002-08-24 10:30:36 +0000 |
commit | 1ee52e8b14da3cb35956f266b963050ccee5da7b (patch) | |
tree | fff8cf71fd1977e2c7b29b971f401a8eac71049b | |
parent | 933d10d308d67708b79f78dc00ae705af6a18f43 (diff) | |
download | busybox-w32-1ee52e8b14da3cb35956f266b963050ccee5da7b.tar.gz busybox-w32-1ee52e8b14da3cb35956f266b963050ccee5da7b.tar.bz2 busybox-w32-1ee52e8b14da3cb35956f266b963050ccee5da7b.zip |
Run through indent, use braces
-rw-r--r-- | archival/gunzip.c | 172 |
1 files changed, 90 insertions, 82 deletions
diff --git a/archival/gunzip.c b/archival/gunzip.c index 4ab197f09..e379ccf10 100644 --- a/archival/gunzip.c +++ b/archival/gunzip.c | |||
@@ -71,90 +71,95 @@ const int gunzip_force = 2; | |||
71 | const int gunzip_test = 4; | 71 | const int gunzip_test = 4; |
72 | const int gunzip_verbose = 8; | 72 | const int gunzip_verbose = 8; |
73 | 73 | ||
74 | static int gunzip_file (const char *path, int flags) | 74 | static int gunzip_file(const char *path, int flags) |
75 | { | 75 | { |
76 | FILE *in_file, *out_file; | 76 | FILE *in_file, *out_file; |
77 | struct stat stat_buf; | 77 | struct stat stat_buf; |
78 | const char *delete_path = NULL; | 78 | const char *delete_path = NULL; |
79 | char *out_path = NULL; | 79 | char *out_path = NULL; |
80 | 80 | ||
81 | if (path == NULL || strcmp (path, "-") == 0) { | 81 | if (path == NULL || strcmp(path, "-") == 0) { |
82 | in_file = stdin; | 82 | in_file = stdin; |
83 | flags |= gunzip_to_stdout; | 83 | flags |= gunzip_to_stdout; |
84 | } else { | 84 | } else { |
85 | if ((in_file = wfopen(path, "r")) == NULL) | 85 | if ((in_file = wfopen(path, "r")) == NULL) { |
86 | return -1; | 86 | return -1; |
87 | 87 | } | |
88 | if (flags & gunzip_verbose) { | 88 | if (flags & gunzip_verbose) { |
89 | fprintf(stderr, "%s:\t", path); | 89 | fprintf(stderr, "%s:\t", path); |
90 | } | ||
91 | |||
92 | /* set the buffer size */ | ||
93 | setvbuf(in_file, NULL, _IOFBF, 0x8000); | ||
94 | |||
95 | /* Get the time stamp on the input file. */ | ||
96 | if (stat(path, &stat_buf) < 0) { | ||
97 | error_msg_and_die("Couldn't stat file %s", path); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | /* Check that the input is sane. */ | ||
102 | if (isatty(fileno(in_file)) && (flags & gunzip_force) == 0) { | ||
103 | error_msg_and_die | ||
104 | ("compressed data not read from terminal. Use -f to force it."); | ||
90 | } | 105 | } |
91 | 106 | ||
92 | /* set the buffer size */ | 107 | /* Set output filename and number */ |
93 | setvbuf(in_file, NULL, _IOFBF, 0x8000); | 108 | if (flags & gunzip_test) { |
109 | out_file = xfopen("/dev/null", "w"); /* why does test use filenum 2 ? */ | ||
110 | } else if (flags & gunzip_to_stdout) { | ||
111 | out_file = stdout; | ||
112 | } else { | ||
113 | char *extension; | ||
114 | int length = strlen(path); | ||
115 | |||
116 | extension = strrchr(path, '.'); | ||
117 | if (extension && strcmp(extension, ".gz") == 0) { | ||
118 | length -= 3; | ||
119 | } else if (extension && strcmp(extension, ".tgz") == 0) { | ||
120 | length -= 4; | ||
121 | } else { | ||
122 | error_msg_and_die("Invalid extension"); | ||
123 | } | ||
124 | out_path = xstrndup(path, length); | ||
94 | 125 | ||
95 | /* Get the time stamp on the input file. */ | 126 | /* Open output file */ |
96 | if (stat(path, &stat_buf) < 0) { | 127 | out_file = xfopen(out_path, "w"); |
97 | error_msg_and_die("Couldn't stat file %s", path); | 128 | |
129 | /* Set permissions on the file */ | ||
130 | chmod(out_path, stat_buf.st_mode); | ||
98 | } | 131 | } |
99 | } | 132 | |
100 | 133 | /* do the decompression, and cleanup */ | |
101 | /* Check that the input is sane. */ | 134 | if (unzip(in_file, out_file) == 0) { |
102 | if (isatty(fileno(in_file)) && (flags & gunzip_force) == 0) | 135 | /* Success, remove .gz file */ |
103 | error_msg_and_die("compressed data not read from terminal. Use -f to force it."); | 136 | if (!(flags & gunzip_to_stdout)) { |
104 | 137 | delete_path = path; | |
105 | /* Set output filename and number */ | 138 | } |
106 | if (flags & gunzip_test) { | 139 | if (flags & gunzip_verbose) { |
107 | out_file = xfopen("/dev/null", "w"); /* why does test use filenum 2 ? */ | 140 | fprintf(stderr, "OK\n"); |
108 | } else if (flags & gunzip_to_stdout) { | 141 | } |
109 | out_file = stdout; | ||
110 | } else { | ||
111 | char *extension; | ||
112 | int length = strlen(path); | ||
113 | |||
114 | extension = strrchr(path, '.'); | ||
115 | if (extension && strcmp(extension, ".gz") == 0) { | ||
116 | length -= 3; | ||
117 | } else if (extension && strcmp(extension, ".tgz") == 0) { | ||
118 | length -= 4; | ||
119 | } else { | 142 | } else { |
120 | error_msg_and_die("Invalid extension"); | 143 | /* remove failed attempt */ |
144 | delete_path = out_path; | ||
121 | } | 145 | } |
122 | out_path = xstrndup(path, length); | 146 | |
123 | 147 | if (out_file != stdout) { | |
124 | /* Open output file */ | 148 | fclose(out_file); |
125 | out_file = xfopen(out_path, "w"); | ||
126 | |||
127 | /* Set permissions on the file */ | ||
128 | chmod(out_path, stat_buf.st_mode); | ||
129 | } | ||
130 | |||
131 | /* do the decompression, and cleanup */ | ||
132 | if (unzip(in_file, out_file) == 0) { | ||
133 | /* Success, remove .gz file */ | ||
134 | if ( !(flags & gunzip_to_stdout )) | ||
135 | delete_path = path; | ||
136 | if (flags & gunzip_verbose) { | ||
137 | fprintf(stderr, "OK\n"); | ||
138 | } | 149 | } |
139 | } else { | 150 | if (in_file != stdin) { |
140 | /* remove failed attempt */ | 151 | fclose(in_file); |
141 | delete_path = out_path; | ||
142 | } | ||
143 | |||
144 | if (out_file != stdout) | ||
145 | fclose(out_file); | ||
146 | if (in_file != stdin) | ||
147 | fclose(in_file); | ||
148 | |||
149 | if (delete_path && !(flags & gunzip_test)) { | ||
150 | if (unlink(delete_path) < 0) { | ||
151 | error_msg_and_die("Couldn't remove %s", delete_path); | ||
152 | } | 152 | } |
153 | } | ||
154 | 153 | ||
155 | free(out_path); | 154 | if (delete_path && !(flags & gunzip_test)) { |
155 | if (unlink(delete_path) < 0) { | ||
156 | error_msg_and_die("Couldn't remove %s", delete_path); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | free(out_path); | ||
156 | 161 | ||
157 | return 0; | 162 | return 0; |
158 | } | 163 | } |
159 | 164 | ||
160 | extern int gunzip_main(int argc, char **argv) | 165 | extern int gunzip_main(int argc, char **argv) |
@@ -164,8 +169,9 @@ extern int gunzip_main(int argc, char **argv) | |||
164 | int status = EXIT_SUCCESS; | 169 | int status = EXIT_SUCCESS; |
165 | 170 | ||
166 | /* if called as zcat */ | 171 | /* if called as zcat */ |
167 | if (strcmp(applet_name, "zcat") == 0) | 172 | if (strcmp(applet_name, "zcat") == 0) { |
168 | flags |= gunzip_to_stdout; | 173 | flags |= gunzip_to_stdout; |
174 | } | ||
169 | 175 | ||
170 | while ((opt = getopt(argc, argv, "ctfhdqv")) != -1) { | 176 | while ((opt = getopt(argc, argv, "ctfhdqv")) != -1) { |
171 | switch (opt) { | 177 | switch (opt) { |
@@ -181,25 +187,27 @@ extern int gunzip_main(int argc, char **argv) | |||
181 | case 'v': | 187 | case 'v': |
182 | flags |= gunzip_verbose; | 188 | flags |= gunzip_verbose; |
183 | break; | 189 | break; |
184 | case 'd': /* Used to convert gzip to gunzip. */ | 190 | case 'd': /* Used to convert gzip to gunzip. */ |
185 | break; | 191 | break; |
186 | case 'q': | 192 | case 'q': |
187 | error_msg("-q option not supported, ignored"); | 193 | error_msg("-q option not supported, ignored"); |
188 | break; | 194 | break; |
189 | case 'h': | 195 | case 'h': |
190 | default: | 196 | default: |
191 | show_usage(); /* exit's inside usage */ | 197 | show_usage(); /* exit's inside usage */ |
192 | } | 198 | } |
193 | } | 199 | } |
194 | 200 | ||
195 | if (optind == argc) { | 201 | if (optind == argc) { |
196 | if (gunzip_file (NULL, flags) < 0) | 202 | if (gunzip_file(NULL, flags) < 0) { |
197 | status = EXIT_FAILURE; | 203 | status = EXIT_FAILURE; |
204 | } | ||
198 | } else { | 205 | } else { |
199 | for (i = optind; i < argc; i++) { | 206 | for (i = optind; i < argc; i++) { |
200 | if (gunzip_file (argv[i], flags) < 0) | 207 | if (gunzip_file(argv[i], flags) < 0) { |
201 | status = EXIT_FAILURE; | 208 | status = EXIT_FAILURE; |
202 | } | 209 | } |
210 | } | ||
203 | } | 211 | } |
204 | return status; | 212 | return status; |
205 | } | 213 | } |