aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-06-08 13:05:39 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-06-08 13:05:39 +0000
commitc14d39e83a7f55ab9b92e98673a281fd6565c32d (patch)
treef1cfe7f071b228cf7f1a732046cabf18fa9421b8
parentdef8260219797b0f9f734915f4918f34e85e7049 (diff)
downloadbusybox-w32-c14d39e83a7f55ab9b92e98673a281fd6565c32d.tar.gz
busybox-w32-c14d39e83a7f55ab9b92e98673a281fd6565c32d.tar.bz2
busybox-w32-c14d39e83a7f55ab9b92e98673a281fd6565c32d.zip
rmp: add optional support for bz2 data. +50 bytes of code
-rw-r--r--archival/Config.in7
-rw-r--r--archival/bbunzip.c6
-rw-r--r--archival/libunarchive/decompress_bunzip2.c4
-rw-r--r--archival/libunarchive/decompress_unlzma.c2
-rw-r--r--archival/libunarchive/decompress_unzip.c4
-rw-r--r--archival/libunarchive/get_header_tar_bz2.c2
-rw-r--r--archival/libunarchive/get_header_tar_gz.c2
-rw-r--r--archival/libunarchive/get_header_tar_lzma.c2
-rw-r--r--archival/rpm.c25
-rw-r--r--archival/rpm2cpio.c2
-rw-r--r--docs/keep_data_small.txt2
-rw-r--r--include/unarchive.h8
12 files changed, 42 insertions, 24 deletions
diff --git a/archival/Config.in b/archival/Config.in
index 2741982c0..661c71ccf 100644
--- a/archival/Config.in
+++ b/archival/Config.in
@@ -133,6 +133,13 @@ config RPM
133 help 133 help
134 Mini RPM applet - queries and extracts RPM packages. 134 Mini RPM applet - queries and extracts RPM packages.
135 135
136config FEATURE_RPM_BZ2
137 bool "Enable handling of rpms with bzip2-compressed data inside"
138 default n
139 depends on RPM
140 help
141 Enable handling of rpms with bzip2-compressed data inside.
142
136config TAR 143config TAR
137 bool "tar" 144 bool "tar"
138 default n 145 default n
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index 83b5637cd..bd1526b20 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -155,7 +155,7 @@ char* make_new_name_bunzip2(char *filename)
155static 155static
156USE_DESKTOP(long long) int unpack_bunzip2(void) 156USE_DESKTOP(long long) int unpack_bunzip2(void)
157{ 157{
158 return uncompressStream(STDIN_FILENO, STDOUT_FILENO); 158 return unpack_bz2_stream(STDIN_FILENO, STDOUT_FILENO);
159} 159}
160 160
161int bunzip2_main(int argc, char **argv); 161int bunzip2_main(int argc, char **argv);
@@ -242,7 +242,7 @@ USE_DESKTOP(long long) int unpack_gunzip(void)
242 status = uncompress(STDIN_FILENO, STDOUT_FILENO); 242 status = uncompress(STDIN_FILENO, STDOUT_FILENO);
243 } else if (magic2 == 0x8b) { 243 } else if (magic2 == 0x8b) {
244 check_header_gzip_or_die(STDIN_FILENO); 244 check_header_gzip_or_die(STDIN_FILENO);
245 status = inflate_gunzip(STDIN_FILENO, STDOUT_FILENO); 245 status = unpack_gz_stream(STDIN_FILENO, STDOUT_FILENO);
246 } else { 246 } else {
247 goto bad_magic; 247 goto bad_magic;
248 } 248 }
@@ -292,7 +292,7 @@ char* make_new_name_unlzma(char *filename)
292static 292static
293USE_DESKTOP(long long) int unpack_unlzma(void) 293USE_DESKTOP(long long) int unpack_unlzma(void)
294{ 294{
295 return unlzma(STDIN_FILENO, STDOUT_FILENO); 295 return unpack_lzma_stream(STDIN_FILENO, STDOUT_FILENO);
296} 296}
297 297
298int unlzma_main(int argc, char **argv); 298int unlzma_main(int argc, char **argv);
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c
index a9d5d686b..fe1d3ff1c 100644
--- a/archival/libunarchive/decompress_bunzip2.c
+++ b/archival/libunarchive/decompress_bunzip2.c
@@ -700,7 +700,7 @@ void dealloc_bunzip(bunzip_data *bd)
700/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */ 700/* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */
701 701
702USE_DESKTOP(long long) int 702USE_DESKTOP(long long) int
703uncompressStream(int src_fd, int dst_fd) 703unpack_bz2_stream(int src_fd, int dst_fd)
704{ 704{
705 USE_DESKTOP(long long total_written = 0;) 705 USE_DESKTOP(long long total_written = 0;)
706 char *outbuf; 706 char *outbuf;
@@ -751,7 +751,7 @@ static char *const bunzip_errors[] = {
751/* Dumb little test thing, decompress stdin to stdout */ 751/* Dumb little test thing, decompress stdin to stdout */
752int main(int argc, char **argv) 752int main(int argc, char **argv)
753{ 753{
754 int i = uncompressStream(0, 1); 754 int i = unpack_bz2_stream(0, 1);
755 char c; 755 char c;
756 756
757 if (i < 0) 757 if (i < 0)
diff --git a/archival/libunarchive/decompress_unlzma.c b/archival/libunarchive/decompress_unlzma.c
index 15a0275b4..907e44e94 100644
--- a/archival/libunarchive/decompress_unlzma.c
+++ b/archival/libunarchive/decompress_unlzma.c
@@ -228,7 +228,7 @@ enum {
228 228
229 229
230USE_DESKTOP(long long) int 230USE_DESKTOP(long long) int
231unlzma(int src_fd, int dst_fd) 231unpack_lzma_stream(int src_fd, int dst_fd)
232{ 232{
233 USE_DESKTOP(long long total_written = 0;) 233 USE_DESKTOP(long long total_written = 0;)
234 lzma_header_t header; 234 lzma_header_t header;
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c
index 19ce5097a..c698763d3 100644
--- a/archival/libunarchive/decompress_unzip.c
+++ b/archival/libunarchive/decompress_unzip.c
@@ -981,7 +981,7 @@ static int inflate_get_next_window(STATE_PARAM_ONLY)
981} 981}
982 982
983 983
984/* Called from inflate_gunzip() and inflate_unzip() */ 984/* Called from unpack_gz_stream() and inflate_unzip() */
985/* NB: bytebuffer is allocated here but freeing it is left to the caller! */ 985/* NB: bytebuffer is allocated here but freeing it is left to the caller! */
986static USE_DESKTOP(long long) int 986static USE_DESKTOP(long long) int
987inflate_unzip_internal(STATE_PARAM int in, int out) 987inflate_unzip_internal(STATE_PARAM int in, int out)
@@ -1056,7 +1056,7 @@ inflate_unzip(inflate_unzip_result *res, unsigned bufsize, int in, int out)
1056 1056
1057 1057
1058USE_DESKTOP(long long) int 1058USE_DESKTOP(long long) int
1059inflate_gunzip(int in, int out) 1059unpack_gz_stream(int in, int out)
1060{ 1060{
1061 uint32_t stored_crc = 0; 1061 uint32_t stored_crc = 0;
1062 unsigned count; 1062 unsigned count;
diff --git a/archival/libunarchive/get_header_tar_bz2.c b/archival/libunarchive/get_header_tar_bz2.c
index d8715c0bb..e11f44cad 100644
--- a/archival/libunarchive/get_header_tar_bz2.c
+++ b/archival/libunarchive/get_header_tar_bz2.c
@@ -11,7 +11,7 @@ char get_header_tar_bz2(archive_handle_t *archive_handle)
11 /* Can't lseek over pipes */ 11 /* Can't lseek over pipes */
12 archive_handle->seek = seek_by_read; 12 archive_handle->seek = seek_by_read;
13 13
14 archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompressStream); 14 archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream);
15 archive_handle->offset = 0; 15 archive_handle->offset = 0;
16 while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; 16 while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
17 17
diff --git a/archival/libunarchive/get_header_tar_gz.c b/archival/libunarchive/get_header_tar_gz.c
index 69126e0ba..85070d978 100644
--- a/archival/libunarchive/get_header_tar_gz.c
+++ b/archival/libunarchive/get_header_tar_gz.c
@@ -20,7 +20,7 @@ char get_header_tar_gz(archive_handle_t *archive_handle)
20 20
21 check_header_gzip_or_die(archive_handle->src_fd); 21 check_header_gzip_or_die(archive_handle->src_fd);
22 22
23 archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip); 23 archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream);
24 archive_handle->offset = 0; 24 archive_handle->offset = 0;
25 while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; 25 while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
26 26
diff --git a/archival/libunarchive/get_header_tar_lzma.c b/archival/libunarchive/get_header_tar_lzma.c
index 5c02767de..771f664f2 100644
--- a/archival/libunarchive/get_header_tar_lzma.c
+++ b/archival/libunarchive/get_header_tar_lzma.c
@@ -14,7 +14,7 @@ char get_header_tar_lzma(archive_handle_t * archive_handle)
14 /* Can't lseek over pipes */ 14 /* Can't lseek over pipes */
15 archive_handle->seek = seek_by_read; 15 archive_handle->seek = seek_by_read;
16 16
17 archive_handle->src_fd = open_transformer(archive_handle->src_fd, unlzma); 17 archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream);
18 archive_handle->offset = 0; 18 archive_handle->offset = 0;
19 while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/; 19 while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
20 20
diff --git a/archival/rpm.c b/archival/rpm.c
index 71ed32e41..674ee2640 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -187,10 +187,11 @@ int rpm_main(int argc, char **argv)
187 187
188static void extract_cpio_gz(int fd) 188static void extract_cpio_gz(int fd)
189{ 189{
190 USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
190 archive_handle_t *archive_handle; 191 archive_handle_t *archive_handle;
191 unsigned char magic[2]; 192 unsigned char magic[2];
192 193
193 /* Initialise */ 194 /* Initialize */
194 archive_handle = init_handle(); 195 archive_handle = init_handle();
195 archive_handle->seek = seek_by_read; 196 archive_handle->seek = seek_by_read;
196 //archive_handle->action_header = header_list; 197 //archive_handle->action_header = header_list;
@@ -201,16 +202,26 @@ static void extract_cpio_gz(int fd)
201 archive_handle->offset = 0; 202 archive_handle->offset = 0;
202 203
203 xread(archive_handle->src_fd, &magic, 2); 204 xread(archive_handle->src_fd, &magic, 2);
205 xformer = unpack_gz_stream;
204 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { 206 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
205 bb_error_msg_and_die("invalid gzip magic"); 207 if (ENABLE_FEATURE_RPM_BZ2
206 } 208 && (magic[0] == 0x42) && (magic[1] == 0x5a)) {
207 check_header_gzip_or_die(archive_handle->src_fd); 209 xformer = unpack_bz2_stream;
208 xchdir("/"); /* Install RPM's to root */ 210 /* We can do better, need modifying unpack_bz2_stream to not require
211 * first 2 bytes. Not very hard to do... I mean, TODO :) */
212 xlseek(archive_handle->src_fd, -2, SEEK_CUR);
213 } else
214 bb_error_msg_and_die("no gzip"
215 USE_FEATURE_RPM_BZ2("/bzip")
216 " magic");
217 } else
218 check_header_gzip_or_die(archive_handle->src_fd);
209 219
210 archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip); 220 xchdir("/"); /* Install RPM's to root */
221 archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer);
211 archive_handle->offset = 0; 222 archive_handle->offset = 0;
212 while (get_header_cpio(archive_handle) == EXIT_SUCCESS) 223 while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
213 /* loop */; 224 continue;
214} 225}
215 226
216 227
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 460aeaff2..dcd9265b3 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -80,7 +80,7 @@ int rpm2cpio_main(int argc, char **argv)
80 } 80 }
81 81
82 check_header_gzip_or_die(rpm_fd); 82 check_header_gzip_or_die(rpm_fd);
83 if (inflate_gunzip(rpm_fd, STDOUT_FILENO) < 0) { 83 if (unpack_gz_stream(rpm_fd, STDOUT_FILENO) < 0) {
84 bb_error_msg("error inflating"); 84 bb_error_msg("error inflating");
85 } 85 }
86 86
diff --git a/docs/keep_data_small.txt b/docs/keep_data_small.txt
index 55f4fc95a..f88fe07b0 100644
--- a/docs/keep_data_small.txt
+++ b/docs/keep_data_small.txt
@@ -65,7 +65,7 @@ archival/libunarchive/decompress_unzip.c:
65(see the rest of the file to get the idea) 65(see the rest of the file to get the idea)
66 66
67This example completely eliminates globals in that module. 67This example completely eliminates globals in that module.
68Required memory is allocated in inflate_gunzip() [its main module] 68Required memory is allocated in unpack_gz_stream() [its main module]
69and then passed down to all subroutines which need to access 'globals' 69and then passed down to all subroutines which need to access 'globals'
70as a parameter. 70as a parameter.
71 71
diff --git a/include/unarchive.h b/include/unarchive.h
index 8b2da5646..c4e875f39 100644
--- a/include/unarchive.h
+++ b/include/unarchive.h
@@ -101,7 +101,6 @@ extern void data_align(archive_handle_t *archive_handle, const unsigned short bo
101extern const llist_t *find_list_entry(const llist_t *list, const char *filename); 101extern const llist_t *find_list_entry(const llist_t *list, const char *filename);
102extern const llist_t *find_list_entry2(const llist_t *list, const char *filename); 102extern const llist_t *find_list_entry2(const llist_t *list, const char *filename);
103 103
104extern USE_DESKTOP(long long) int uncompressStream(int src_fd, int dst_fd);
105/* A bit of bunzip2 internals are exposed for compressed help support: */ 104/* A bit of bunzip2 internals are exposed for compressed help support: */
106typedef struct bunzip_data bunzip_data; 105typedef struct bunzip_data bunzip_data;
107int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf, int len); 106int start_bunzip(bunzip_data **bdp, int in_fd, const unsigned char *inbuf, int len);
@@ -113,9 +112,10 @@ typedef struct inflate_unzip_result {
113 uint32_t crc; 112 uint32_t crc;
114} inflate_unzip_result; 113} inflate_unzip_result;
115 114
116extern USE_DESKTOP(long long) int inflate_unzip(inflate_unzip_result *res, unsigned bufsize, int in, int out); 115extern USE_DESKTOP(long long) int unpack_bz2_stream(int src_fd, int dst_fd);
117extern USE_DESKTOP(long long) int inflate_gunzip(int in, int out); 116extern USE_DESKTOP(long long) int inflate_unzip(inflate_unzip_result *res, unsigned bufsize, int src_fd, int dst_fd);
118extern USE_DESKTOP(long long) int unlzma(int src_fd, int dst_fd); 117extern USE_DESKTOP(long long) int unpack_gz_stream(int src_fd, int dst_fd);
118extern USE_DESKTOP(long long) int unpack_lzma_stream(int src_fd, int dst_fd);
119 119
120extern int open_transformer(int src_fd, 120extern int open_transformer(int src_fd,
121 USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd)); 121 USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd));