diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-06 14:19:19 +0000 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-05-06 14:19:19 +0000 |
commit | 27653adc8b7ebe44bd357511de53d0c14eef0894 (patch) | |
tree | d1c9b0facbcca408a18d75f93aa507e96927ef31 /libbb | |
parent | b8ba6b66f5d730efcf13dbbb3f9362dd6840d93b (diff) | |
download | busybox-w32-27653adc8b7ebe44bd357511de53d0c14eef0894.tar.gz busybox-w32-27653adc8b7ebe44bd357511de53d0c14eef0894.tar.bz2 busybox-w32-27653adc8b7ebe44bd357511de53d0c14eef0894.zip |
rpm: code shrink. Now uses open_zipped's logic (factored out into setup_unzip_on_fd())
function old new delta
setup_unzip_on_fd - 80 +80
open_zipped 176 113 -63
rpm_main 1672 1355 -317
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 0/2 up/down: 80/-380) Total: -300 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/read.c | 97 |
1 files changed, 55 insertions, 42 deletions
diff --git a/libbb/read.c b/libbb/read.c index 06ce29718..503216eb5 100644 --- a/libbb/read.c +++ b/libbb/read.c | |||
@@ -6,7 +6,6 @@ | |||
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 8 | */ |
9 | |||
10 | #include "libbb.h" | 9 | #include "libbb.h" |
11 | 10 | ||
12 | #define ZIPPED (ENABLE_FEATURE_SEAMLESS_LZMA \ | 11 | #define ZIPPED (ENABLE_FEATURE_SEAMLESS_LZMA \ |
@@ -16,7 +15,7 @@ | |||
16 | ) | 15 | ) |
17 | 16 | ||
18 | #if ZIPPED | 17 | #if ZIPPED |
19 | #include "unarchive.h" | 18 | # include "unarchive.h" |
20 | #endif | 19 | #endif |
21 | 20 | ||
22 | ssize_t FAST_FUNC safe_read(int fd, void *buf, size_t count) | 21 | ssize_t FAST_FUNC safe_read(int fd, void *buf, size_t count) |
@@ -306,14 +305,11 @@ void* FAST_FUNC xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) | |||
306 | return buf; | 305 | return buf; |
307 | } | 306 | } |
308 | 307 | ||
309 | int FAST_FUNC open_zipped(const char *fname) | 308 | #if ZIPPED |
309 | int FAST_FUNC setup_unzip_on_fd(int fd /*, int fail_if_not_detected*/) | ||
310 | { | 310 | { |
311 | #if !ZIPPED | 311 | const int fail_if_not_detected = 1; |
312 | return open(fname, O_RDONLY); | ||
313 | #else | ||
314 | unsigned char magic[2]; | 312 | unsigned char magic[2]; |
315 | char *sfx; | ||
316 | int fd; | ||
317 | #if BB_MMU | 313 | #if BB_MMU |
318 | IF_DESKTOP(long long) int FAST_FUNC (*xformer)(int src_fd, int dst_fd); | 314 | IF_DESKTOP(long long) int FAST_FUNC (*xformer)(int src_fd, int dst_fd); |
319 | enum { xformer_prog = 0 }; | 315 | enum { xformer_prog = 0 }; |
@@ -322,6 +318,56 @@ int FAST_FUNC open_zipped(const char *fname) | |||
322 | const char *xformer_prog; | 318 | const char *xformer_prog; |
323 | #endif | 319 | #endif |
324 | 320 | ||
321 | /* .gz and .bz2 both have 2-byte signature, and their | ||
322 | * unpack_XXX_stream wants this header skipped. */ | ||
323 | xread(fd, &magic, 2); | ||
324 | #if ENABLE_FEATURE_SEAMLESS_GZ | ||
325 | # if BB_MMU | ||
326 | xformer = unpack_gz_stream; | ||
327 | # else | ||
328 | xformer_prog = "gunzip"; | ||
329 | # endif | ||
330 | #endif | ||
331 | if (!ENABLE_FEATURE_SEAMLESS_GZ | ||
332 | || magic[0] != 0x1f || magic[1] != 0x8b | ||
333 | ) { | ||
334 | if (!ENABLE_FEATURE_SEAMLESS_BZ2 | ||
335 | || magic[0] != 'B' || magic[1] != 'Z' | ||
336 | ) { | ||
337 | if (fail_if_not_detected) | ||
338 | bb_error_msg_and_die("no gzip" | ||
339 | IF_FEATURE_SEAMLESS_BZ2("/bzip2") | ||
340 | " magic"); | ||
341 | xlseek(fd, -2, SEEK_CUR); | ||
342 | return fd; | ||
343 | } | ||
344 | #if BB_MMU | ||
345 | xformer = unpack_bz2_stream; | ||
346 | #else | ||
347 | xformer_prog = "bunzip2"; | ||
348 | #endif | ||
349 | } else { | ||
350 | #if !BB_MMU | ||
351 | /* NOMMU version of open_transformer execs | ||
352 | * an external unzipper that wants | ||
353 | * file position at the start of the file */ | ||
354 | xlseek(fd, -2, SEEK_CUR); | ||
355 | #endif | ||
356 | } | ||
357 | open_transformer(fd, xformer, xformer_prog); | ||
358 | |||
359 | return fd; | ||
360 | } | ||
361 | #endif /* ZIPPED */ | ||
362 | |||
363 | int FAST_FUNC open_zipped(const char *fname) | ||
364 | { | ||
365 | #if !ZIPPED | ||
366 | return open(fname, O_RDONLY); | ||
367 | #else | ||
368 | char *sfx; | ||
369 | int fd; | ||
370 | |||
325 | fd = open(fname, O_RDONLY); | 371 | fd = open(fname, O_RDONLY); |
326 | if (fd < 0) | 372 | if (fd < 0) |
327 | return fd; | 373 | return fd; |
@@ -335,40 +381,7 @@ int FAST_FUNC open_zipped(const char *fname) | |||
335 | if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, ".gz") == 0) | 381 | if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, ".gz") == 0) |
336 | || (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, ".bz2") == 0) | 382 | || (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, ".bz2") == 0) |
337 | ) { | 383 | ) { |
338 | /* .gz and .bz2 both have 2-byte signature, and their | 384 | setup_unzip_on_fd(fd /*, fail_if_not_detected: 1*/); |
339 | * unpack_XXX_stream wants this header skipped. */ | ||
340 | xread(fd, &magic, 2); | ||
341 | #if ENABLE_FEATURE_SEAMLESS_GZ | ||
342 | #if BB_MMU | ||
343 | xformer = unpack_gz_stream; | ||
344 | #else | ||
345 | xformer_prog = "gunzip"; | ||
346 | #endif | ||
347 | #endif | ||
348 | if (!ENABLE_FEATURE_SEAMLESS_GZ | ||
349 | || magic[0] != 0x1f || magic[1] != 0x8b | ||
350 | ) { | ||
351 | if (!ENABLE_FEATURE_SEAMLESS_BZ2 | ||
352 | || magic[0] != 'B' || magic[1] != 'Z' | ||
353 | ) { | ||
354 | bb_error_msg_and_die("no gzip" | ||
355 | IF_FEATURE_SEAMLESS_BZ2("/bzip2") | ||
356 | " magic"); | ||
357 | } | ||
358 | #if BB_MMU | ||
359 | xformer = unpack_bz2_stream; | ||
360 | #else | ||
361 | xformer_prog = "bunzip2"; | ||
362 | #endif | ||
363 | } else { | ||
364 | #if !BB_MMU | ||
365 | /* NOMMU version of open_transformer execs | ||
366 | * an external unzipper that wants | ||
367 | * file position at the start of the file */ | ||
368 | xlseek(fd, 0, SEEK_SET); | ||
369 | #endif | ||
370 | } | ||
371 | open_transformer(fd, xformer, xformer_prog); | ||
372 | } | 385 | } |
373 | } | 386 | } |
374 | 387 | ||