diff options
author | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-07-16 08:14:35 +0000 |
---|---|---|
committer | landley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2006-07-16 08:14:35 +0000 |
commit | a15cdc358e5f9d1cb517e2b2e490ac209b0dfa17 (patch) | |
tree | fac906b4fa40a68c53cecf20215a7a25b3b1cab6 /archival/unzip.c | |
parent | a4b7afd4143063613cf88fb5304803e424f5c72a (diff) | |
download | busybox-w32-a15cdc358e5f9d1cb517e2b2e490ac209b0dfa17.tar.gz busybox-w32-a15cdc358e5f9d1cb517e2b2e490ac209b0dfa17.tar.bz2 busybox-w32-a15cdc358e5f9d1cb517e2b2e490ac209b0dfa17.zip |
Cleaup read() and write() variants, plus a couple of new functions like
xlseek and fdlength() for the new mkswap.
git-svn-id: svn://busybox.net/trunk/busybox@15703 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'archival/unzip.c')
-rw-r--r-- | archival/unzip.c | 61 |
1 files changed, 17 insertions, 44 deletions
diff --git a/archival/unzip.c b/archival/unzip.c index 8ba39e9af..632cc8551 100644 --- a/archival/unzip.c +++ b/archival/unzip.c | |||
@@ -32,28 +32,10 @@ | |||
32 | #include "unarchive.h" | 32 | #include "unarchive.h" |
33 | #include "busybox.h" | 33 | #include "busybox.h" |
34 | 34 | ||
35 | #if BB_BIG_ENDIAN | 35 | #define ZIP_FILEHEADER_MAGIC SWAP_LE32(0x04034b50) |
36 | static inline unsigned short | 36 | #define ZIP_CDS_MAGIC SWAP_LE32(0x02014b50) |
37 | __swap16(unsigned short x) { | 37 | #define ZIP_CDS_END_MAGIC SWAP_LE32(0x06054b50) |
38 | return (((uint16_t)(x) & 0xFF) << 8) | (((uint16_t)(x) & 0xFF00) >> 8); | 38 | #define ZIP_DD_MAGIC SWAP_LE32(0x08074b50) |
39 | } | ||
40 | |||
41 | static inline uint32_t | ||
42 | __swap32(uint32_t x) { | ||
43 | return (((x & 0xFF) << 24) | | ||
44 | ((x & 0xFF00) << 8) | | ||
45 | ((x & 0xFF0000) >> 8) | | ||
46 | ((x & 0xFF000000) >> 24)); | ||
47 | } | ||
48 | #else /* it's little-endian */ | ||
49 | # define __swap16(x) (x) | ||
50 | # define __swap32(x) (x) | ||
51 | #endif /* BB_BIG_ENDIAN */ | ||
52 | |||
53 | #define ZIP_FILEHEADER_MAGIC __swap32(0x04034b50) | ||
54 | #define ZIP_CDS_MAGIC __swap32(0x02014b50) | ||
55 | #define ZIP_CDS_END_MAGIC __swap32(0x06054b50) | ||
56 | #define ZIP_DD_MAGIC __swap32(0x08074b50) | ||
57 | 39 | ||
58 | extern unsigned int gunzip_crc; | 40 | extern unsigned int gunzip_crc; |
59 | extern unsigned int gunzip_bytes_out; | 41 | extern unsigned int gunzip_bytes_out; |
@@ -83,13 +65,6 @@ static void unzip_skip(int fd, off_t skip) | |||
83 | } | 65 | } |
84 | } | 66 | } |
85 | 67 | ||
86 | static void unzip_read(int fd, void *buf, size_t count) | ||
87 | { | ||
88 | if (bb_xread(fd, buf, count) != count) { | ||
89 | bb_error_msg_and_die(bb_msg_read_error); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | static void unzip_create_leading_dirs(char *fn) | 68 | static void unzip_create_leading_dirs(char *fn) |
94 | { | 69 | { |
95 | /* Create all leading directories */ | 70 | /* Create all leading directories */ |
@@ -248,7 +223,7 @@ int unzip_main(int argc, char **argv) | |||
248 | unsigned int magic; | 223 | unsigned int magic; |
249 | 224 | ||
250 | /* Check magic number */ | 225 | /* Check magic number */ |
251 | unzip_read(src_fd, &magic, 4); | 226 | xread(src_fd, &magic, 4); |
252 | if (magic == ZIP_CDS_MAGIC) { | 227 | if (magic == ZIP_CDS_MAGIC) { |
253 | break; | 228 | break; |
254 | } else if (magic != ZIP_FILEHEADER_MAGIC) { | 229 | } else if (magic != ZIP_FILEHEADER_MAGIC) { |
@@ -256,19 +231,17 @@ int unzip_main(int argc, char **argv) | |||
256 | } | 231 | } |
257 | 232 | ||
258 | /* Read the file header */ | 233 | /* Read the file header */ |
259 | unzip_read(src_fd, zip_header.raw, 26); | 234 | xread(src_fd, zip_header.raw, 26); |
260 | #if BB_BIG_ENDIAN | 235 | zip_header.formated.version = SWAP_LE32(zip_header.formated.version); |
261 | zip_header.formated.version = __swap16(zip_header.formated.version); | 236 | zip_header.formated.flags = SWAP_LE32(zip_header.formated.flags); |
262 | zip_header.formated.flags = __swap16(zip_header.formated.flags); | 237 | zip_header.formated.method = SWAP_LE32(zip_header.formated.method); |
263 | zip_header.formated.method = __swap16(zip_header.formated.method); | 238 | zip_header.formated.modtime = SWAP_LE32(zip_header.formated.modtime); |
264 | zip_header.formated.modtime = __swap16(zip_header.formated.modtime); | 239 | zip_header.formated.moddate = SWAP_LE32(zip_header.formated.moddate); |
265 | zip_header.formated.moddate = __swap16(zip_header.formated.moddate); | 240 | zip_header.formated.crc32 = SWAP_LE32(zip_header.formated.crc32); |
266 | zip_header.formated.crc32 = __swap32(zip_header.formated.crc32); | 241 | zip_header.formated.cmpsize = SWAP_LE32(zip_header.formated.cmpsize); |
267 | zip_header.formated.cmpsize = __swap32(zip_header.formated.cmpsize); | 242 | zip_header.formated.ucmpsize = SWAP_LE32(zip_header.formated.ucmpsize); |
268 | zip_header.formated.ucmpsize = __swap32(zip_header.formated.ucmpsize); | 243 | zip_header.formated.filename_len = SWAP_LE32(zip_header.formated.filename_len); |
269 | zip_header.formated.filename_len = __swap16(zip_header.formated.filename_len); | 244 | zip_header.formated.extra_len = SWAP_LE32(zip_header.formated.extra_len); |
270 | zip_header.formated.extra_len = __swap16(zip_header.formated.extra_len); | ||
271 | #endif /* BB_BIG_ENDIAN */ | ||
272 | if ((zip_header.formated.method != 0) && (zip_header.formated.method != 8)) { | 245 | if ((zip_header.formated.method != 0) && (zip_header.formated.method != 8)) { |
273 | bb_error_msg_and_die("Unsupported compression method %d", zip_header.formated.method); | 246 | bb_error_msg_and_die("Unsupported compression method %d", zip_header.formated.method); |
274 | } | 247 | } |
@@ -276,7 +249,7 @@ int unzip_main(int argc, char **argv) | |||
276 | /* Read filename */ | 249 | /* Read filename */ |
277 | free(dst_fn); | 250 | free(dst_fn); |
278 | dst_fn = xzalloc(zip_header.formated.filename_len + 1); | 251 | dst_fn = xzalloc(zip_header.formated.filename_len + 1); |
279 | unzip_read(src_fd, dst_fn, zip_header.formated.filename_len); | 252 | xread(src_fd, dst_fn, zip_header.formated.filename_len); |
280 | 253 | ||
281 | /* Skip extra header bytes */ | 254 | /* Skip extra header bytes */ |
282 | unzip_skip(src_fd, zip_header.formated.extra_len); | 255 | unzip_skip(src_fd, zip_header.formated.extra_len); |