aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
Diffstat (limited to 'archival')
-rw-r--r--archival/bunzip2.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/archival/bunzip2.c b/archival/bunzip2.c
index da9808e82..290681dd3 100644
--- a/archival/bunzip2.c
+++ b/archival/bunzip2.c
@@ -1,4 +1,5 @@
1/* Modified for busybox by Glenn McGrath <bug1@optushome.com.au> */ 1/* Modified for busybox by Glenn McGrath <bug1@optushome.com.au> */
2/* Added support output to stdout by Thomas Lundquist <thomasez@zelow.no> */
2/*-- 3/*--
3 This file is a part of bzip2 and/or libbzip2, a program and 4 This file is a part of bzip2 and/or libbzip2, a program and
4 library for lossless, block-sorting data compression. 5 library for lossless, block-sorting data compression.
@@ -56,6 +57,7 @@
56#include <stdlib.h> 57#include <stdlib.h>
57#include <stdio.h> 58#include <stdio.h>
58#include <string.h> 59#include <string.h>
60#include <getopt.h>
59#include <busybox.h> 61#include <busybox.h>
60 62
61//#define TRUE 1 63//#define TRUE 1
@@ -2316,15 +2318,38 @@ errhandler_io:
2316 2318
2317int bunzip2_main(int argc, char **argv) 2319int bunzip2_main(int argc, char **argv)
2318{ 2320{
2321 const int bunzip_to_stdout = 1;
2322 int flags = 0;
2323 int opt = 0;
2324
2319 FILE *src_stream; 2325 FILE *src_stream;
2320 FILE *dst_stream; 2326 FILE *dst_stream;
2321 char *save_name; 2327 char *save_name;
2322 char *save_name_ptr; 2328 char *save_name_ptr;
2323 if (argc != 2) { 2329
2330 /* if called as bzcat */
2331 if (strcmp(applet_name, "bzcat") == 0)
2332 flags |= bunzip_to_stdout;
2333
2334 while ((opt = getopt(argc, argv, "ch")) != -1) {
2335 switch (opt) {
2336 case 'c':
2337 flags |= bunzip_to_stdout;
2338 break;
2339 case 'h':
2340 default:
2341 show_usage(); /* exit's inside usage */
2342 }
2343 }
2344
2345 save_name = xstrdup(argv[optind]);
2346
2347 if (save_name == NULL) {
2324 show_usage(); 2348 show_usage();
2325 } 2349 }
2326 src_stream = xfopen(argv[1], "r"); 2350
2327 save_name = xstrdup(argv[1]); 2351 src_stream = xfopen(argv[optind], "r");
2352
2328 save_name_ptr = strrchr(save_name, '.'); 2353 save_name_ptr = strrchr(save_name, '.');
2329 if (save_name_ptr == NULL) { 2354 if (save_name_ptr == NULL) {
2330 return(FALSE); 2355 return(FALSE);
@@ -2333,7 +2358,12 @@ int bunzip2_main(int argc, char **argv)
2333 error_msg("Invalid extension, expected .bz2"); 2358 error_msg("Invalid extension, expected .bz2");
2334 } 2359 }
2335 *save_name_ptr = '\0'; 2360 *save_name_ptr = '\0';
2336 dst_stream = xfopen(save_name, "w"); 2361
2362 if (flags & bunzip_to_stdout) {
2363 dst_stream = stdout;
2364 } else {
2365 dst_stream = xfopen(save_name, "w");
2366 }
2337 uncompressStream(src_stream, dst_stream); 2367 uncompressStream(src_stream, dst_stream);
2338 2368
2339 return(TRUE); 2369 return(TRUE);