aboutsummaryrefslogtreecommitdiff
path: root/libbb/read.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2010-05-11 03:53:57 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2010-05-11 03:53:57 +0200
commitbfa1b2e8e8aaddcf849011a12cb2ac634b27f339 (patch)
tree4a5fbaef1371fb8b2ca504e753fa2a31d25234d4 /libbb/read.c
parent6334390aef2eb52cc827a6d18f942b2b8a04ef59 (diff)
downloadbusybox-bfa1b2e8e8aaddcf849011a12cb2ac634b27f339.tar.gz
randomtest fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/read.c')
-rw-r--r--libbb/read.c61
1 files changed, 31 insertions, 30 deletions
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;