diff options
-rw-r--r-- | archival/bbunzip.c | 123 |
1 files changed, 48 insertions, 75 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c index 824b0027f..1c8d0ab55 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c | |||
@@ -4,7 +4,6 @@ | |||
4 | * | 4 | * |
5 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 5 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
6 | */ | 6 | */ |
7 | |||
8 | #include "libbb.h" | 7 | #include "libbb.h" |
9 | #include "unarchive.h" | 8 | #include "unarchive.h" |
10 | 9 | ||
@@ -141,8 +140,7 @@ int FAST_FUNC bbunpack(char **argv, | |||
141 | return exitcode; | 140 | return exitcode; |
142 | } | 141 | } |
143 | 142 | ||
144 | #if ENABLE_BUNZIP2 || ENABLE_UNLZMA || ENABLE_UNCOMPRESS | 143 | #if ENABLE_UNCOMPRESS || ENABLE_BUNZIP2 || ENABLE_UNLZMA || ENABLE_UNXZ |
145 | |||
146 | static | 144 | static |
147 | char* make_new_name_generic(char *filename, const char *expected_ext) | 145 | char* make_new_name_generic(char *filename, const char *expected_ext) |
148 | { | 146 | { |
@@ -155,42 +153,40 @@ char* make_new_name_generic(char *filename, const char *expected_ext) | |||
155 | *extension = '\0'; | 153 | *extension = '\0'; |
156 | return filename; | 154 | return filename; |
157 | } | 155 | } |
158 | |||
159 | #endif | 156 | #endif |
160 | 157 | ||
161 | 158 | ||
162 | /* | 159 | /* |
163 | * Modified for busybox by Glenn McGrath | 160 | * Uncompress applet for busybox (c) 2002 Glenn McGrath |
164 | * Added support output to stdout by Thomas Lundquist <thomasez@zelow.no> | ||
165 | * | 161 | * |
166 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 162 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
167 | */ | 163 | */ |
168 | 164 | #if ENABLE_UNCOMPRESS | |
169 | #if ENABLE_BUNZIP2 | ||
170 | |||
171 | static | 165 | static |
172 | char* make_new_name_bunzip2(char *filename) | 166 | char* make_new_name_uncompress(char *filename) |
173 | { | 167 | { |
174 | return make_new_name_generic(filename, "bz2"); | 168 | return make_new_name_generic(filename, "Z"); |
175 | } | 169 | } |
176 | |||
177 | static | 170 | static |
178 | IF_DESKTOP(long long) int unpack_bunzip2(unpack_info_t *info UNUSED_PARAM) | 171 | IF_DESKTOP(long long) int unpack_uncompress(unpack_info_t *info UNUSED_PARAM) |
179 | { | 172 | { |
180 | return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO); | 173 | IF_DESKTOP(long long) int status = -1; |
181 | } | ||
182 | 174 | ||
183 | int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 175 | if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) { |
184 | int bunzip2_main(int argc UNUSED_PARAM, char **argv) | 176 | bb_error_msg("invalid magic"); |
177 | } else { | ||
178 | status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO); | ||
179 | } | ||
180 | return status; | ||
181 | } | ||
182 | int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
183 | int uncompress_main(int argc UNUSED_PARAM, char **argv) | ||
185 | { | 184 | { |
186 | getopt32(argv, "cfvdt"); | 185 | getopt32(argv, "cf"); |
187 | argv += optind; | 186 | argv += optind; |
188 | if (applet_name[2] == 'c') | ||
189 | option_mask32 |= OPT_STDOUT; | ||
190 | 187 | ||
191 | return bbunpack(argv, make_new_name_bunzip2, unpack_bunzip2); | 188 | return bbunpack(argv, make_new_name_uncompress, unpack_uncompress); |
192 | } | 189 | } |
193 | |||
194 | #endif | 190 | #endif |
195 | 191 | ||
196 | 192 | ||
@@ -221,9 +217,7 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv) | |||
221 | * See the license_msg below and the file COPYING for the software license. | 217 | * See the license_msg below and the file COPYING for the software license. |
222 | * See the file algorithm.doc for the compression algorithms and file formats. | 218 | * See the file algorithm.doc for the compression algorithms and file formats. |
223 | */ | 219 | */ |
224 | |||
225 | #if ENABLE_GUNZIP | 220 | #if ENABLE_GUNZIP |
226 | |||
227 | static | 221 | static |
228 | char* make_new_name_gunzip(char *filename) | 222 | char* make_new_name_gunzip(char *filename) |
229 | { | 223 | { |
@@ -249,7 +243,6 @@ char* make_new_name_gunzip(char *filename) | |||
249 | } | 243 | } |
250 | return filename; | 244 | return filename; |
251 | } | 245 | } |
252 | |||
253 | static | 246 | static |
254 | IF_DESKTOP(long long) int unpack_gunzip(unpack_info_t *info) | 247 | IF_DESKTOP(long long) int unpack_gunzip(unpack_info_t *info) |
255 | { | 248 | { |
@@ -277,7 +270,6 @@ IF_DESKTOP(long long) int unpack_gunzip(unpack_info_t *info) | |||
277 | } | 270 | } |
278 | return status; | 271 | return status; |
279 | } | 272 | } |
280 | |||
281 | /* | 273 | /* |
282 | * Linux kernel build uses gzip -d -n. We accept and ignore it. | 274 | * Linux kernel build uses gzip -d -n. We accept and ignore it. |
283 | * Man page says: | 275 | * Man page says: |
@@ -291,7 +283,6 @@ IF_DESKTOP(long long) int unpack_gunzip(unpack_info_t *info) | |||
291 | * gzip: always save the original file name and time stamp (this is the default) | 283 | * gzip: always save the original file name and time stamp (this is the default) |
292 | * gunzip: restore the original file name and time stamp if present. | 284 | * gunzip: restore the original file name and time stamp if present. |
293 | */ | 285 | */ |
294 | |||
295 | int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 286 | int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
296 | int gunzip_main(int argc UNUSED_PARAM, char **argv) | 287 | int gunzip_main(int argc UNUSED_PARAM, char **argv) |
297 | { | 288 | { |
@@ -303,7 +294,36 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) | |||
303 | 294 | ||
304 | return bbunpack(argv, make_new_name_gunzip, unpack_gunzip); | 295 | return bbunpack(argv, make_new_name_gunzip, unpack_gunzip); |
305 | } | 296 | } |
297 | #endif | ||
298 | |||
299 | |||
300 | /* | ||
301 | * Modified for busybox by Glenn McGrath | ||
302 | * Added support output to stdout by Thomas Lundquist <thomasez@zelow.no> | ||
303 | * | ||
304 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
305 | */ | ||
306 | #if ENABLE_BUNZIP2 | ||
307 | static | ||
308 | char* make_new_name_bunzip2(char *filename) | ||
309 | { | ||
310 | return make_new_name_generic(filename, "bz2"); | ||
311 | } | ||
312 | static | ||
313 | IF_DESKTOP(long long) int unpack_bunzip2(unpack_info_t *info UNUSED_PARAM) | ||
314 | { | ||
315 | return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO); | ||
316 | } | ||
317 | int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
318 | int bunzip2_main(int argc UNUSED_PARAM, char **argv) | ||
319 | { | ||
320 | getopt32(argv, "cfvdt"); | ||
321 | argv += optind; | ||
322 | if (applet_name[2] == 'c') /* bzcat */ | ||
323 | option_mask32 |= OPT_STDOUT; | ||
306 | 324 | ||
325 | return bbunpack(argv, make_new_name_bunzip2, unpack_bunzip2); | ||
326 | } | ||
307 | #endif | 327 | #endif |
308 | 328 | ||
309 | 329 | ||
@@ -315,21 +335,17 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) | |||
315 | * | 335 | * |
316 | * Licensed under GPL v2, see file LICENSE in this tarball for details. | 336 | * Licensed under GPL v2, see file LICENSE in this tarball for details. |
317 | */ | 337 | */ |
318 | |||
319 | #if ENABLE_UNLZMA | 338 | #if ENABLE_UNLZMA |
320 | |||
321 | static | 339 | static |
322 | char* make_new_name_unlzma(char *filename) | 340 | char* make_new_name_unlzma(char *filename) |
323 | { | 341 | { |
324 | return make_new_name_generic(filename, "lzma"); | 342 | return make_new_name_generic(filename, "lzma"); |
325 | } | 343 | } |
326 | |||
327 | static | 344 | static |
328 | IF_DESKTOP(long long) int unpack_unlzma(unpack_info_t *info UNUSED_PARAM) | 345 | IF_DESKTOP(long long) int unpack_unlzma(unpack_info_t *info UNUSED_PARAM) |
329 | { | 346 | { |
330 | return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO); | 347 | return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO); |
331 | } | 348 | } |
332 | |||
333 | int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 349 | int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
334 | int unlzma_main(int argc UNUSED_PARAM, char **argv) | 350 | int unlzma_main(int argc UNUSED_PARAM, char **argv) |
335 | { | 351 | { |
@@ -346,62 +362,20 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv) | |||
346 | argv += optind; | 362 | argv += optind; |
347 | return bbunpack(argv, make_new_name_unlzma, unpack_unlzma); | 363 | return bbunpack(argv, make_new_name_unlzma, unpack_unlzma); |
348 | } | 364 | } |
349 | |||
350 | #endif | 365 | #endif |
351 | 366 | ||
352 | 367 | ||
353 | /* | ||
354 | * Uncompress applet for busybox (c) 2002 Glenn McGrath | ||
355 | * | ||
356 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
357 | */ | ||
358 | |||
359 | #if ENABLE_UNCOMPRESS | ||
360 | |||
361 | static | ||
362 | char* make_new_name_uncompress(char *filename) | ||
363 | { | ||
364 | return make_new_name_generic(filename, "Z"); | ||
365 | } | ||
366 | |||
367 | static | ||
368 | IF_DESKTOP(long long) int unpack_uncompress(unpack_info_t *info UNUSED_PARAM) | ||
369 | { | ||
370 | IF_DESKTOP(long long) int status = -1; | ||
371 | |||
372 | if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) { | ||
373 | bb_error_msg("invalid magic"); | ||
374 | } else { | ||
375 | status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO); | ||
376 | } | ||
377 | return status; | ||
378 | } | ||
379 | |||
380 | int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
381 | int uncompress_main(int argc UNUSED_PARAM, char **argv) | ||
382 | { | ||
383 | getopt32(argv, "cf"); | ||
384 | argv += optind; | ||
385 | |||
386 | return bbunpack(argv, make_new_name_uncompress, unpack_uncompress); | ||
387 | } | ||
388 | |||
389 | #endif | ||
390 | |||
391 | #if ENABLE_UNXZ | 368 | #if ENABLE_UNXZ |
392 | |||
393 | static | 369 | static |
394 | char* make_new_name_unxz(char *filename) | 370 | char* make_new_name_unxz(char *filename) |
395 | { | 371 | { |
396 | return make_new_name_generic(filename, "xz"); | 372 | return make_new_name_generic(filename, "xz"); |
397 | } | 373 | } |
398 | |||
399 | static | 374 | static |
400 | IF_DESKTOP(long long) int unpack_unxz(unpack_info_t *info UNUSED_PARAM) | 375 | IF_DESKTOP(long long) int unpack_unxz(unpack_info_t *info UNUSED_PARAM) |
401 | { | 376 | { |
402 | return unpack_xz_stream_stdin(); | 377 | return unpack_xz_stream_stdin(); |
403 | } | 378 | } |
404 | |||
405 | int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 379 | int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
406 | int unxz_main(int argc UNUSED_PARAM, char **argv) | 380 | int unxz_main(int argc UNUSED_PARAM, char **argv) |
407 | { | 381 | { |
@@ -418,5 +392,4 @@ int unxz_main(int argc UNUSED_PARAM, char **argv) | |||
418 | argv += optind; | 392 | argv += optind; |
419 | return bbunpack(argv, make_new_name_unxz, unpack_unxz); | 393 | return bbunpack(argv, make_new_name_unxz, unpack_unxz); |
420 | } | 394 | } |
421 | |||
422 | #endif | 395 | #endif |