diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-30 19:43:44 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-30 19:43:44 +0200 |
commit | 620e863ba24fe9e0126d1540e89a531264021a77 (patch) | |
tree | c761483f73c045f510690c64a89d6ca56b511a7f | |
parent | fa5ea17b5f6457d888a30afeff87420b7fe0348a (diff) | |
download | busybox-w32-620e863ba24fe9e0126d1540e89a531264021a77.tar.gz busybox-w32-620e863ba24fe9e0126d1540e89a531264021a77.tar.bz2 busybox-w32-620e863ba24fe9e0126d1540e89a531264021a77.zip |
bzip2 decompression: simple code shrink
function old new delta
unpack_bz2_stream_prime 60 55 -5
get_header_tar 1508 1496 -12
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/libunarchive/decompress_bunzip2.c | 6 | ||||
-rw-r--r-- | archival/libunarchive/get_header_tar.c | 9 |
2 files changed, 9 insertions, 6 deletions
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c index cd8df086e..bdbd39ac2 100644 --- a/archival/libunarchive/decompress_bunzip2.c +++ b/archival/libunarchive/decompress_bunzip2.c | |||
@@ -692,9 +692,9 @@ unpack_bz2_stream(int src_fd, int dst_fd) | |||
692 | IF_DESKTOP(long long) int FAST_FUNC | 692 | IF_DESKTOP(long long) int FAST_FUNC |
693 | unpack_bz2_stream_prime(int src_fd, int dst_fd) | 693 | unpack_bz2_stream_prime(int src_fd, int dst_fd) |
694 | { | 694 | { |
695 | unsigned char magic[2]; | 695 | uint16_t magic2; |
696 | xread(src_fd, magic, 2); | 696 | xread(src_fd, &magic2, 2); |
697 | if (magic[0] != 'B' || magic[1] != 'Z') { | 697 | if (magic2 != BZIP2_MAGIC) { |
698 | bb_error_msg_and_die("invalid magic"); | 698 | bb_error_msg_and_die("invalid magic"); |
699 | } | 699 | } |
700 | return unpack_bz2_stream(src_fd, dst_fd); | 700 | return unpack_bz2_stream(src_fd, dst_fd); |
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index 21bbc9715..d5c92359c 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c | |||
@@ -196,27 +196,30 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
196 | ) { | 196 | ) { |
197 | #if ENABLE_FEATURE_TAR_AUTODETECT | 197 | #if ENABLE_FEATURE_TAR_AUTODETECT |
198 | char FAST_FUNC (*get_header_ptr)(archive_handle_t *); | 198 | char FAST_FUNC (*get_header_ptr)(archive_handle_t *); |
199 | uint16_t magic2; | ||
199 | 200 | ||
200 | autodetect: | 201 | autodetect: |
202 | magic2 = *(uint16_t*)tar.name; | ||
201 | /* tar gz/bz autodetect: check for gz/bz2 magic. | 203 | /* tar gz/bz autodetect: check for gz/bz2 magic. |
202 | * If we see the magic, and it is the very first block, | 204 | * If we see the magic, and it is the very first block, |
203 | * we can switch to get_header_tar_gz/bz2/lzma(). | 205 | * we can switch to get_header_tar_gz/bz2/lzma(). |
204 | * Needs seekable fd. I wish recv(MSG_PEEK) works | 206 | * Needs seekable fd. I wish recv(MSG_PEEK) works |
205 | * on any fd... */ | 207 | * on any fd... */ |
206 | # if ENABLE_FEATURE_SEAMLESS_GZ | 208 | # if ENABLE_FEATURE_SEAMLESS_GZ |
207 | if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */ | 209 | if (magic2 == GZIP_MAGIC) { |
208 | get_header_ptr = get_header_tar_gz; | 210 | get_header_ptr = get_header_tar_gz; |
209 | } else | 211 | } else |
210 | # endif | 212 | # endif |
211 | # if ENABLE_FEATURE_SEAMLESS_BZ2 | 213 | # if ENABLE_FEATURE_SEAMLESS_BZ2 |
212 | if (tar.name[0] == 'B' && tar.name[1] == 'Z' | 214 | if (magic2 == BZIP2_MAGIC |
213 | && tar.name[2] == 'h' && isdigit(tar.name[3]) | 215 | && tar.name[2] == 'h' && isdigit(tar.name[3]) |
214 | ) { /* bzip2 */ | 216 | ) { /* bzip2 */ |
215 | get_header_ptr = get_header_tar_bz2; | 217 | get_header_ptr = get_header_tar_bz2; |
216 | } else | 218 | } else |
217 | # endif | 219 | # endif |
218 | # if ENABLE_FEATURE_SEAMLESS_XZ | 220 | # if ENABLE_FEATURE_SEAMLESS_XZ |
219 | //TODO | 221 | //TODO: if (magic2 == XZ_MAGIC1)... |
222 | //else | ||
220 | # endif | 223 | # endif |
221 | goto err; | 224 | goto err; |
222 | /* Two different causes for lseek() != 0: | 225 | /* Two different causes for lseek() != 0: |