From bfa1b2e8e8aaddcf849011a12cb2ac634b27f339 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 11 May 2010 03:53:57 +0200 Subject: randomtest fixes Signed-off-by: Denys Vlasenko --- libbb/read.c | 61 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'libbb') diff --git a/libbb/read.c b/libbb/read.c index 21e005c6f..f3af144f0 100644 --- a/libbb/read.c +++ b/libbb/read.c @@ -321,44 +321,45 @@ int FAST_FUNC setup_unzip_on_fd(int fd /*, int fail_if_not_detected*/) /* .gz and .bz2 both have 2-byte signature, and their * unpack_XXX_stream wants this header skipped. */ xread(fd, &magic, 2); -#if ENABLE_FEATURE_SEAMLESS_GZ + if (ENABLE_FEATURE_SEAMLESS_GZ + && magic[0] == 0x1f && magic[1] == 0x8b + ) { # if BB_MMU - xformer = unpack_gz_stream; + xformer = unpack_gz_stream; # else - xformer_prog = "gunzip"; + xformer_prog = "gunzip"; # endif -#endif - if (!ENABLE_FEATURE_SEAMLESS_GZ - || magic[0] != 0x1f || magic[1] != 0x8b + goto found_magic; + } + if (ENABLE_FEATURE_SEAMLESS_BZ2 + && magic[0] == 'B' && magic[1] == 'Z' ) { - if (!ENABLE_FEATURE_SEAMLESS_BZ2 - || magic[0] != 'B' || magic[1] != 'Z' - ) { - +# if BB_MMU + xformer = unpack_bz2_stream; +# else + xformer_prog = "bunzip2"; +# endif + goto found_magic; + } // TODO: xz format support. rpm adopted it, "rpm -i FILE.rpm" badly needs this. // Signature: 0xFD, '7', 'z', 'X', 'Z', 0x00 // More info at: http://tukaani.org/xz/xz-file-format.txt - if (fail_if_not_detected) - bb_error_msg_and_die("no gzip" - IF_FEATURE_SEAMLESS_BZ2("/bzip2") - " magic"); - xlseek(fd, -2, SEEK_CUR); - return fd; - } -#if BB_MMU - xformer = unpack_bz2_stream; -#else - xformer_prog = "bunzip2"; -#endif - } else { -#if !BB_MMU - /* NOMMU version of open_transformer execs - * an external unzipper that wants - * file position at the start of the file */ - xlseek(fd, -2, SEEK_CUR); -#endif - } + /* No known magic seen */ + if (fail_if_not_detected) + bb_error_msg_and_die("no gzip" + IF_FEATURE_SEAMLESS_BZ2("/bzip2") + " magic"); + xlseek(fd, -2, SEEK_CUR); + return fd; + + found_magic: +# if !BB_MMU + /* NOMMU version of open_transformer execs + * an external unzipper that wants + * file position at the start of the file */ + xlseek(fd, -2, SEEK_CUR); +# endif open_transformer(fd, xformer, xformer_prog); return fd; -- cgit v1.2.3