aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
Diffstat (limited to 'archival')
-rw-r--r--archival/bunzip2.c39
1 files changed, 22 insertions, 17 deletions
diff --git a/archival/bunzip2.c b/archival/bunzip2.c
index b0a11fd83..678779e64 100644
--- a/archival/bunzip2.c
+++ b/archival/bunzip2.c
@@ -58,6 +58,7 @@
58#include <stdio.h> 58#include <stdio.h>
59#include <string.h> 59#include <string.h>
60#include <getopt.h> 60#include <getopt.h>
61#include <unistd.h>
61#include <busybox.h> 62#include <busybox.h>
62 63
63//#define TRUE 1 64//#define TRUE 1
@@ -2319,45 +2320,49 @@ errhandler_io:
2319int bunzip2_main(int argc, char **argv) 2320int bunzip2_main(int argc, char **argv)
2320{ 2321{
2321 const int bunzip_to_stdout = 1; 2322 const int bunzip_to_stdout = 1;
2323 const int bunzip_force = 2;
2322 int flags = 0; 2324 int flags = 0;
2323 int opt = 0; 2325 int opt = 0;
2324 2326
2325 FILE *src_stream; 2327 FILE *src_stream;
2326 FILE *dst_stream; 2328 FILE *dst_stream;
2327 char *save_name; 2329 char *save_name = NULL;
2328 char *save_name_ptr;
2329 2330
2330 /* if called as bzcat */ 2331 /* if called as bzcat */
2331 if (strcmp(applet_name, "bzcat") == 0) 2332 if (strcmp(applet_name, "bzcat") == 0)
2332 flags |= bunzip_to_stdout; 2333 flags |= bunzip_to_stdout;
2333 2334
2334 while ((opt = getopt(argc, argv, "ch")) != -1) { 2335 while ((opt = getopt(argc, argv, "cfh")) != -1) {
2335 switch (opt) { 2336 switch (opt) {
2336 case 'c': 2337 case 'c':
2337 flags |= bunzip_to_stdout; 2338 flags |= bunzip_to_stdout;
2338 break; 2339 break;
2340 case 'f':
2341 flags |= bunzip_force;
2342 break;
2339 case 'h': 2343 case 'h':
2340 default: 2344 default:
2341 show_usage(); /* exit's inside usage */ 2345 show_usage(); /* exit's inside usage */
2342 } 2346 }
2343 } 2347 }
2344 2348
2345 save_name = xstrdup(argv[optind]); 2349 /* Set input filename and number */
2346 2350 if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
2347 if (save_name == NULL) { 2351 flags |= bunzip_to_stdout;
2348 show_usage(); 2352 src_stream = stdin;
2349 } 2353 } else {
2350 2354 /* Open input file */
2351 src_stream = xfopen(argv[optind], "r"); 2355 src_stream = xfopen(argv[optind], "r");
2352 2356
2353 save_name_ptr = strrchr(save_name, '.'); 2357 save_name = xstrdup(argv[optind]);
2354 if (save_name_ptr == NULL) { 2358 if (strcmp(save_name + strlen(save_name) - 4, ".bz2") != 0)
2355 return(FALSE); 2359 error_msg_and_die("Invalid extension");
2356 } 2360 save_name[strlen(save_name) - 4] = '\0';
2357 if (strcmp(save_name_ptr, ".bz2") != 0) {
2358 error_msg("Invalid extension, expected .bz2");
2359 } 2361 }
2360 *save_name_ptr = '\0'; 2362
2363 /* Check that the input is sane. */
2364 if (isatty(fileno(src_stream)) && (flags & bunzip_force) == 0)
2365 error_msg_and_die("compressed data not read from terminal. Use -f to force it.");
2361 2366
2362 if (flags & bunzip_to_stdout) { 2367 if (flags & bunzip_to_stdout) {
2363 dst_stream = stdout; 2368 dst_stream = stdout;