aboutsummaryrefslogtreecommitdiff
path: root/archival/bbunzip.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-23 12:12:03 +0000
committerRon Yorston <rmy@pobox.com>2012-03-23 12:12:03 +0000
commitb0f54743e36af163ae2530c381c485bb29df13dc (patch)
treecda4cfeaae6e47fe4f14c1b566092be4da9affc4 /archival/bbunzip.c
parent40514a0309939f2446f0d4ed9600cad5de396e7f (diff)
parentba88826c66411affc1da3614742b454654f7298a (diff)
downloadbusybox-w32-b0f54743e36af163ae2530c381c485bb29df13dc.tar.gz
busybox-w32-b0f54743e36af163ae2530c381c485bb29df13dc.tar.bz2
busybox-w32-b0f54743e36af163ae2530c381c485bb29df13dc.zip
Merge branch 'busybox' into merge
Conflicts: Makefile.flags
Diffstat (limited to 'archival/bbunzip.c')
-rw-r--r--archival/bbunzip.c72
1 files changed, 17 insertions, 55 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index c96e5396a..66a046052 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
@@ -184,16 +184,9 @@ char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
184 184
185#if ENABLE_UNCOMPRESS 185#if ENABLE_UNCOMPRESS
186static 186static
187IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(unpack_info_t *info UNUSED_PARAM) 187IF_DESKTOP(long long) int FAST_FUNC unpack_uncompress(transformer_aux_data_t *aux)
188{ 188{
189 IF_DESKTOP(long long) int status = -1; 189 return unpack_Z_stream(aux, STDIN_FILENO, STDOUT_FILENO);
190
191 if ((xread_char(STDIN_FILENO) != 0x1f) || (xread_char(STDIN_FILENO) != 0x9d)) {
192 bb_error_msg("invalid magic");
193 } else {
194 status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO);
195 }
196 return status;
197} 190}
198int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 191int uncompress_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
199int uncompress_main(int argc UNUSED_PARAM, char **argv) 192int uncompress_main(int argc UNUSED_PARAM, char **argv)
@@ -281,31 +274,9 @@ char* FAST_FUNC make_new_name_gunzip(char *filename, const char *expected_ext UN
281 return filename; 274 return filename;
282} 275}
283static 276static
284IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(unpack_info_t *info) 277IF_DESKTOP(long long) int FAST_FUNC unpack_gunzip(transformer_aux_data_t *aux)
285{ 278{
286 IF_DESKTOP(long long) int status = -1; 279 return unpack_gz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
287
288 /* do the decompression, and cleanup */
289 if (xread_char(STDIN_FILENO) == 0x1f) {
290 unsigned char magic2;
291
292 magic2 = xread_char(STDIN_FILENO);
293 if (ENABLE_FEATURE_SEAMLESS_Z && magic2 == 0x9d) {
294 status = unpack_Z_stream(STDIN_FILENO, STDOUT_FILENO);
295 } else if (magic2 == 0x8b) {
296 status = unpack_gz_stream_with_info(STDIN_FILENO, STDOUT_FILENO, info);
297 } else {
298 goto bad_magic;
299 }
300 if (status < 0) {
301 bb_error_msg("error inflating");
302 }
303 } else {
304 bad_magic:
305 bb_error_msg("invalid magic");
306 /* status is still == -1 */
307 }
308 return status;
309} 280}
310/* 281/*
311 * Linux kernel build uses gzip -d -n. We accept and ignore it. 282 * Linux kernel build uses gzip -d -n. We accept and ignore it.
@@ -354,9 +325,9 @@ int gunzip_main(int argc UNUSED_PARAM, char **argv)
354//applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat)) 325//applet:IF_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, BB_DIR_USR_BIN, BB_SUID_DROP, bzcat))
355#if ENABLE_BUNZIP2 326#if ENABLE_BUNZIP2
356static 327static
357IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(unpack_info_t *info UNUSED_PARAM) 328IF_DESKTOP(long long) int FAST_FUNC unpack_bunzip2(transformer_aux_data_t *aux)
358{ 329{
359 return unpack_bz2_stream_prime(STDIN_FILENO, STDOUT_FILENO); 330 return unpack_bz2_stream(aux, STDIN_FILENO, STDOUT_FILENO);
360} 331}
361int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 332int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
362int bunzip2_main(int argc UNUSED_PARAM, char **argv) 333int bunzip2_main(int argc UNUSED_PARAM, char **argv)
@@ -422,9 +393,9 @@ int bunzip2_main(int argc UNUSED_PARAM, char **argv)
422 393
423#if ENABLE_UNLZMA 394#if ENABLE_UNLZMA
424static 395static
425IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(unpack_info_t *info UNUSED_PARAM) 396IF_DESKTOP(long long) int FAST_FUNC unpack_unlzma(transformer_aux_data_t *aux)
426{ 397{
427 return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO); 398 return unpack_lzma_stream(aux, STDIN_FILENO, STDOUT_FILENO);
428} 399}
429int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 400int unlzma_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
430int unlzma_main(int argc UNUSED_PARAM, char **argv) 401int unlzma_main(int argc UNUSED_PARAM, char **argv)
@@ -447,18 +418,9 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv)
447 418
448#if ENABLE_UNXZ 419#if ENABLE_UNXZ
449static 420static
450IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(unpack_info_t *info UNUSED_PARAM) 421IF_DESKTOP(long long) int FAST_FUNC unpack_unxz(transformer_aux_data_t *aux)
451{ 422{
452 struct { 423 return unpack_xz_stream(aux, STDIN_FILENO, STDOUT_FILENO);
453 uint32_t v1;
454 uint16_t v2;
455 } magic;
456 xread(STDIN_FILENO, &magic, 6);
457 if (magic.v1 != XZ_MAGIC1a || magic.v2 != XZ_MAGIC2a) {
458 bb_error_msg("invalid magic");
459 return -1;
460 }
461 return unpack_xz_stream(STDIN_FILENO, STDOUT_FILENO);
462} 424}
463int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 425int unxz_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
464int unxz_main(int argc UNUSED_PARAM, char **argv) 426int unxz_main(int argc UNUSED_PARAM, char **argv)