diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2013-02-28 18:06:09 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2013-02-28 18:06:09 +0100 |
commit | 8e96efa32314ec5a4e6ace9a6fe7a1694e2e7d90 (patch) | |
tree | 8c58dedb2b63b49f5b18f232ba7a08117f9464b3 | |
parent | f2d8478e560fd77b45dbea7993d6219a5b635b2e (diff) | |
download | busybox-w32-8e96efa32314ec5a4e6ace9a6fe7a1694e2e7d90.tar.gz busybox-w32-8e96efa32314ec5a4e6ace9a6fe7a1694e2e7d90.tar.bz2 busybox-w32-8e96efa32314ec5a4e6ace9a6fe7a1694e2e7d90.zip |
zcat: if seamless uncompressors are defined, autodetect file's format
function old new delta
bbunpack 526 622 +96
packed_usage 29335 29341 +6
gunzip_main 64 67 +3
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/bbunzip.c | 54 |
1 files changed, 40 insertions, 14 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c index 46f99cf78..54dc2f5f1 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c | |||
@@ -14,6 +14,7 @@ enum { | |||
14 | OPT_VERBOSE = 1 << 2, | 14 | OPT_VERBOSE = 1 << 2, |
15 | OPT_DECOMPRESS = 1 << 3, | 15 | OPT_DECOMPRESS = 1 << 3, |
16 | OPT_TEST = 1 << 4, | 16 | OPT_TEST = 1 << 4, |
17 | SEAMLESS_MAGIC = (1 << 31) * SEAMLESS_COMPRESSION, | ||
17 | }; | 18 | }; |
18 | 19 | ||
19 | static | 20 | static |
@@ -39,7 +40,7 @@ int FAST_FUNC bbunpack(char **argv, | |||
39 | ) | 40 | ) |
40 | { | 41 | { |
41 | struct stat stat_buf; | 42 | struct stat stat_buf; |
42 | IF_DESKTOP(long long) int status; | 43 | IF_DESKTOP(long long) int status = 0; |
43 | char *filename, *new_name; | 44 | char *filename, *new_name; |
44 | smallint exitcode = 0; | 45 | smallint exitcode = 0; |
45 | transformer_aux_data_t aux; | 46 | transformer_aux_data_t aux; |
@@ -54,14 +55,23 @@ int FAST_FUNC bbunpack(char **argv, | |||
54 | 55 | ||
55 | /* Open src */ | 56 | /* Open src */ |
56 | if (filename) { | 57 | if (filename) { |
57 | if (stat(filename, &stat_buf) != 0) { | 58 | if (!(option_mask32 & SEAMLESS_MAGIC)) { |
58 | bb_simple_perror_msg(filename); | 59 | if (stat(filename, &stat_buf) != 0) { |
60 | err_name: | ||
61 | bb_simple_perror_msg(filename); | ||
59 | err: | 62 | err: |
60 | exitcode = 1; | 63 | exitcode = 1; |
61 | goto free_name; | 64 | goto free_name; |
65 | } | ||
66 | if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0)) | ||
67 | goto err; | ||
68 | } else { | ||
69 | /* "clever zcat" */ | ||
70 | int fd = open_zipped(filename); | ||
71 | if (fd < 0) | ||
72 | goto err_name; | ||
73 | xmove_fd(fd, STDIN_FILENO); | ||
62 | } | 74 | } |
63 | if (open_to_or_warn(STDIN_FILENO, filename, O_RDONLY, 0)) | ||
64 | goto err; | ||
65 | } | 75 | } |
66 | 76 | ||
67 | /* Special cases: test, stdout */ | 77 | /* Special cases: test, stdout */ |
@@ -98,11 +108,23 @@ int FAST_FUNC bbunpack(char **argv, | |||
98 | "use -f to force it"); | 108 | "use -f to force it"); |
99 | } | 109 | } |
100 | 110 | ||
101 | init_transformer_aux_data(&aux); | 111 | if (!(option_mask32 & SEAMLESS_MAGIC)) { |
102 | aux.check_signature = 1; | 112 | init_transformer_aux_data(&aux); |
103 | status = unpacker(&aux); | 113 | aux.check_signature = 1; |
104 | if (status < 0) | 114 | status = unpacker(&aux); |
105 | exitcode = 1; | 115 | if (status < 0) |
116 | exitcode = 1; | ||
117 | } else { | ||
118 | /* "clever zcat" */ | ||
119 | if (!filename) { | ||
120 | if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_detected*/ 0)) | ||
121 | goto err; | ||
122 | } | ||
123 | if (bb_copyfd_eof(STDIN_FILENO, STDOUT_FILENO) < 0) { | ||
124 | /* Disk full, tty closed, etc. No point in continuing */ | ||
125 | xfunc_die(); | ||
126 | } | ||
127 | } | ||
106 | 128 | ||
107 | if (!(option_mask32 & OPT_STDOUT)) | 129 | if (!(option_mask32 & OPT_STDOUT)) |
108 | xclose(STDOUT_FILENO); /* with error check! */ | 130 | xclose(STDOUT_FILENO); /* with error check! */ |
@@ -294,9 +316,13 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv) | |||
294 | { | 316 | { |
295 | getopt32(argv, "cfvdtn"); | 317 | getopt32(argv, "cfvdtn"); |
296 | argv += optind; | 318 | argv += optind; |
297 | /* if called as zcat */ | 319 | |
320 | /* If called as zcat... | ||
321 | * Normally, "zcat" is just "gunzip -c". | ||
322 | * But if seamless magic is enabled, then we are much more clever. | ||
323 | */ | ||
298 | if (applet_name[1] == 'c') | 324 | if (applet_name[1] == 'c') |
299 | option_mask32 |= OPT_STDOUT; | 325 | option_mask32 |= OPT_STDOUT | SEAMLESS_MAGIC; |
300 | 326 | ||
301 | return bbunpack(argv, unpack_gunzip, make_new_name_gunzip, /*unused:*/ NULL); | 327 | return bbunpack(argv, unpack_gunzip, make_new_name_gunzip, /*unused:*/ NULL); |
302 | } | 328 | } |