aboutsummaryrefslogtreecommitdiff
path: root/archival/bbunzip.c
diff options
context:
space:
mode:
Diffstat (limited to 'archival/bbunzip.c')
-rw-r--r--archival/bbunzip.c78
1 files changed, 31 insertions, 47 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index 853c653c0..1bc04ed33 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -33,7 +33,7 @@ char* FAST_FUNC append_ext(char *filename, const char *expected_ext)
33} 33}
34 34
35int FAST_FUNC bbunpack(char **argv, 35int FAST_FUNC bbunpack(char **argv,
36 IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(unpack_info_t *info), 36 IF_DESKTOP(long long) int FAST_FUNC (*unpacker)(transformer_aux_data_t *aux),
37 char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext), 37 char* FAST_FUNC (*make_new_name)(char *filename, const char *expected_ext),
38 const char *expected_ext 38 const char *expected_ext
39) 39)
@@ -42,7 +42,7 @@ int FAST_FUNC bbunpack(char **argv,
42 IF_DESKTOP(long long) int status; 42 IF_DESKTOP(long long) int status;
43 char *filename, *new_name; 43 char *filename, *new_name;
44 smallint exitcode = 0; 44 smallint exitcode = 0;
45 unpack_info_t info; 45 transformer_aux_data_t aux;
46 46
47 do { 47 do {
48 /* NB: new_name is *maybe* malloc'ed! */ 48 /* NB: new_name is *maybe* malloc'ed! */
@@ -98,9 +98,9 @@ int FAST_FUNC bbunpack(char **argv,
98 "use -f to force it"); 98 "use -f to force it");
99 } 99 }
100 100
101 /* memset(&info, 0, sizeof(info)); */ 101 init_transformer_aux_data(&aux);
102 info.mtime = 0; /* so far it has one member only */ 102 aux.check_signature = 1;
103 status = unpacker(&info); 103 status = unpacker(&aux);
104 if (status < 0) 104 if (status < 0)
105 exitcode = 1; 105 exitcode = 1;
106 106
@@ -111,10 +111,10 @@ int FAST_FUNC bbunpack(char **argv,
111 char *del = new_name; 111 char *del = new_name;
112 if (status >= 0) { 112 if (status >= 0) {
113 /* TODO: restore other things? */ 113 /* TODO: restore other things? */
114 if (info.mtime) { 114 if (aux.mtime != 0) {
115 struct timeval times[2]; 115 struct timeval times[2];
116 116
117 times[1].tv_sec = times[0].tv_sec = info.mtime; 117 times[1].tv_sec = times[0].tv_sec = aux.mtime;
118 times[1].tv_usec = times[0].tv_usec = 0; 118 times[1].tv_usec = times[0].tv_usec = 0;
119 /* Note: we closed it first. 119 /* Note: we closed it first.
120 * On some systems calling utimes 120 * On some systems calling utimes
@@ -182,16 +182,9 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
182 182
183#if ENABLE_UNCOMPRESS 183#if ENABLE_UNCOMPRESS
184static 184static
185IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(unpack_info_t *info UNUSED_PARAM) 185IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)
186{ 186{
187 IF_DESKTOP(long long) int status = -1; 187 return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
188
189 if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) {
190 bb_error_msg("invalid magic");
191 } else {
192 status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO);
193 }
194 return status;
195} 188}
196int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 189int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
197int uncompress_main(int argc UNUSED_PARAM, char **argv) 190int uncompress_main(int argc UNUSED_PARAM, char **argv)
@@ -279,30 +272,30 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
279 return filename; 272 return filename;
280} 273}
281static 274static
282IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(unpack_info_t *info) 275IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
283{ 276{
284 IF_DESKTOP(long long) int status = -1; 277 IF_DESKTOP(long long) int status = -1;
278 uint16_t magic2;
285 279
286 /* do the decompression, and cleanup */ 280//TODO: fold below into unpack_gz_stream? Then the whole level of indirection
287 if (xread_char(STDIN_FILENO) == 0x1f) { 281// unpack_FOO() -> unpack_FOO_stream can be collapsed in this module!
288 unsigned char magic2; 282
289 283 aux->check_signature = 0; /* we will check it here, not in unpack_*_stream */
290 magic2 = xread_char(STDIN_FILENO); 284
291 if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == 0x9d) { 285 if (full_read(STDIN_FILENO, &magic2, 2) != 2)
292 status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO); 286 goto bad_magic;
293 } else if (magic2 == 0x8b) { 287 if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == COMPRESS_MAGIC) {
294 status = unpack_gz_stream_with_info(STDIN_FILENO, STDOUT_FILENO, info); 288 status = unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
295 } else { 289 } else if (magic2 == GZIP_MAGIC) {
296 goto bad_magic; 290 status = unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
297 }
298 if (status < 0) {
299 bb_error_msg("error inflating");
300 }
301 } else { 291 } else {
302 bad_magic: 292 bad_magic:
303 bb_error_msg("invalid magic"); 293 bb_error_msg("invalid magic");
304 /* status is still == -1 */ 294 /* status is still == -1 */
305 } 295 }
296 if (status < 0) {
297 bb_error_msg("error inflating");
298 }
306 return status; 299 return status;
307} 300}
308/* 301/*
@@ -352,9 +345,9 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
352//applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat)) 345//applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
353#if ENABLE_BUNZIP2 346#if ENABLE_BUNZIP2
354static 347static
355IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(unpack_info_t *info UNUSED_PARAM) 348IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
356{ 349{
357 return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO); 350 return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO);
358} 351}
359int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 352int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
360int bunzip2_main(int argc UNUSED_PARAM, char **argv) 353int bunzip2_main(int argc UNUSED_PARAM, char **argv)
@@ -420,9 +413,9 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
420 413
421#if ENABLE_UNLZMA 414#if ENABLE_UNLZMA
422static 415static
423IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(unpack_info_t *info UNUSED_PARAM) 416IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
424{ 417{
425 return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO); 418 return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO);
426} 419}
427int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 420int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
428int unlzma_main(int argc UNUSED_PARAM, char **argv) 421int unlzma_main(int argc UNUSED_PARAM, char **argv)
@@ -445,18 +438,9 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
445 438
446#if ENABLE_UNXZ 439#if ENABLE_UNXZ
447static 440static
448IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(unpack_info_t *info UNUSED_PARAM) 441IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
449{ 442{
450 struct { 443 return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
451 uint32_t v1;
452 uint16_t v2;
453 } magic;
454 xread(STDIN_FILENO, &magic, 6);
455 if (magic.v1 != XZ_MAGIC1a || magic.v2 != XZ_MAGIC2a) {
456 bb_error_msg("invalid magic");
457 return -1;
458 }
459 return unpack_xz_stream(STDIN_FILENO, STDOUT_FILENO);
460} 444}
461int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 445int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
462int unxz_main(int argc UNUSED_PARAM, char **argv) 446int unxz_main(int argc UNUSED_PARAM, char **argv)