aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2002-03-27 17:31:01 +0000
committerMatt Kraai <kraai@debian.org>2002-03-27 17:31:01 +0000
commit9cdb0601eb53ffdb3fb6b94bb1336adbc7d59e5c (patch)
treea8c2712e1b703f28ba0ca4ad662227ddea2bf413
parentfa15f702d2e4c7d377d6cf89e950227405622f1b (diff)
downloadbusybox-w32-9cdb0601eb53ffdb3fb6b94bb1336adbc7d59e5c.tar.gz
busybox-w32-9cdb0601eb53ffdb3fb6b94bb1336adbc7d59e5c.tar.bz2
busybox-w32-9cdb0601eb53ffdb3fb6b94bb1336adbc7d59e5c.zip
* archival/bunzip2.c: Include <unistd.h>.
(bunzip2_main): Read data from standard input if FILE argument is `-' or omitted. * include/usage.h (bunzip2_trivial_usage, bunzip2_full_usage): Rewrite. * testsuite/bunzip2/bunzip2-reads-from-standard-input: New.
-rw-r--r--archival/bunzip2.c39
-rw-r--r--include/usage.h9
-rw-r--r--testsuite/bunzip2/bunzip2-reads-from-standard-input2
3 files changed, 29 insertions, 21 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;
diff --git a/include/usage.h b/include/usage.h
index 6692aa520..e7de6f53f 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -52,11 +52,12 @@
52 "bar" 52 "bar"
53 53
54#define bunzip2_trivial_usage \ 54#define bunzip2_trivial_usage \
55 "[-c] FILE" 55 "[OPTION]... [FILE]"
56#define bunzip2_full_usage \ 56#define bunzip2_full_usage \
57 "Uncompress FILE to current directory, stripping its .bz2 extension.\n"\ 57 "Uncompress FILE (or standard input if FILE is '-' or omitted).\n\n" \
58 " -c output to stdout\n"\ 58 "Options:\n" \
59 " -k is assumed" 59 "\t-c\tWrite output to standard output\n" \
60 "\t-f\tForce"
60 61
61#define bzcat_trivial_usage \ 62#define bzcat_trivial_usage \
62 "FILE" 63 "FILE"
diff --git a/testsuite/bunzip2/bunzip2-reads-from-standard-input b/testsuite/bunzip2/bunzip2-reads-from-standard-input
new file mode 100644
index 000000000..7bc842135
--- /dev/null
+++ b/testsuite/bunzip2/bunzip2-reads-from-standard-input
@@ -0,0 +1,2 @@
1echo foo | bzip2 -c | busybox bunzip2 -c > output
2echo foo | cmp - output