* 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.
This commit is contained in:
parent
fa15f702d2
commit
9cdb0601eb
@ -58,6 +58,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <busybox.h>
|
#include <busybox.h>
|
||||||
|
|
||||||
//#define TRUE 1
|
//#define TRUE 1
|
||||||
@ -2319,45 +2320,49 @@ errhandler_io:
|
|||||||
int bunzip2_main(int argc, char **argv)
|
int bunzip2_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const int bunzip_to_stdout = 1;
|
const int bunzip_to_stdout = 1;
|
||||||
|
const int bunzip_force = 2;
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
int opt = 0;
|
int opt = 0;
|
||||||
|
|
||||||
FILE *src_stream;
|
FILE *src_stream;
|
||||||
FILE *dst_stream;
|
FILE *dst_stream;
|
||||||
char *save_name;
|
char *save_name = NULL;
|
||||||
char *save_name_ptr;
|
|
||||||
|
|
||||||
/* if called as bzcat */
|
/* if called as bzcat */
|
||||||
if (strcmp(applet_name, "bzcat") == 0)
|
if (strcmp(applet_name, "bzcat") == 0)
|
||||||
flags |= bunzip_to_stdout;
|
flags |= bunzip_to_stdout;
|
||||||
|
|
||||||
while ((opt = getopt(argc, argv, "ch")) != -1) {
|
while ((opt = getopt(argc, argv, "cfh")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'c':
|
case 'c':
|
||||||
flags |= bunzip_to_stdout;
|
flags |= bunzip_to_stdout;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
flags |= bunzip_force;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
show_usage(); /* exit's inside usage */
|
show_usage(); /* exit's inside usage */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
save_name = xstrdup(argv[optind]);
|
/* Set input filename and number */
|
||||||
|
if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
|
||||||
|
flags |= bunzip_to_stdout;
|
||||||
|
src_stream = stdin;
|
||||||
|
} else {
|
||||||
|
/* Open input file */
|
||||||
|
src_stream = xfopen(argv[optind], "r");
|
||||||
|
|
||||||
if (save_name == NULL) {
|
save_name = xstrdup(argv[optind]);
|
||||||
show_usage();
|
if (strcmp(save_name + strlen(save_name) - 4, ".bz2") != 0)
|
||||||
|
error_msg_and_die("Invalid extension");
|
||||||
|
save_name[strlen(save_name) - 4] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
src_stream = xfopen(argv[optind], "r");
|
/* Check that the input is sane. */
|
||||||
|
if (isatty(fileno(src_stream)) && (flags & bunzip_force) == 0)
|
||||||
save_name_ptr = strrchr(save_name, '.');
|
error_msg_and_die("compressed data not read from terminal. Use -f to force it.");
|
||||||
if (save_name_ptr == NULL) {
|
|
||||||
return(FALSE);
|
|
||||||
}
|
|
||||||
if (strcmp(save_name_ptr, ".bz2") != 0) {
|
|
||||||
error_msg("Invalid extension, expected .bz2");
|
|
||||||
}
|
|
||||||
*save_name_ptr = '\0';
|
|
||||||
|
|
||||||
if (flags & bunzip_to_stdout) {
|
if (flags & bunzip_to_stdout) {
|
||||||
dst_stream = stdout;
|
dst_stream = stdout;
|
||||||
|
@ -52,11 +52,12 @@
|
|||||||
"bar"
|
"bar"
|
||||||
|
|
||||||
#define bunzip2_trivial_usage \
|
#define bunzip2_trivial_usage \
|
||||||
"[-c] FILE"
|
"[OPTION]... [FILE]"
|
||||||
#define bunzip2_full_usage \
|
#define bunzip2_full_usage \
|
||||||
"Uncompress FILE to current directory, stripping its .bz2 extension.\n"\
|
"Uncompress FILE (or standard input if FILE is '-' or omitted).\n\n" \
|
||||||
" -c output to stdout\n"\
|
"Options:\n" \
|
||||||
" -k is assumed"
|
"\t-c\tWrite output to standard output\n" \
|
||||||
|
"\t-f\tForce"
|
||||||
|
|
||||||
#define bzcat_trivial_usage \
|
#define bzcat_trivial_usage \
|
||||||
"FILE"
|
"FILE"
|
||||||
|
2
testsuite/bunzip2/bunzip2-reads-from-standard-input
Normal file
2
testsuite/bunzip2/bunzip2-reads-from-standard-input
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
echo foo | bzip2 -c | busybox bunzip2 -c > output
|
||||||
|
echo foo | cmp - output
|
Loading…
Reference in New Issue
Block a user