aboutsummaryrefslogtreecommitdiff
path: root/archival/bbunzip.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-09 20:49:55 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-09 20:49:55 +0000
commitbebbd8c9baaa7a2da5ac9ab484f54ce3115982d5 (patch)
tree14bbc1d2a6a996403bc823be203a2283caf0d95f /archival/bbunzip.c
parentf25d57e0b40efbd5dcb4ccd38a9c9f054faa9446 (diff)
downloadbusybox-w32-bebbd8c9baaa7a2da5ac9ab484f54ce3115982d5.tar.gz
busybox-w32-bebbd8c9baaa7a2da5ac9ab484f54ce3115982d5.tar.bz2
busybox-w32-bebbd8c9baaa7a2da5ac9ab484f54ce3115982d5.zip
bbunzip: size optimization: ~90 bytes
Diffstat (limited to 'archival/bbunzip.c')
-rw-r--r--archival/bbunzip.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index 3dff946a1..b922fd373 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -127,13 +127,11 @@ int unpack(char **argv,
127 return exitcode; 127 return exitcode;
128} 128}
129 129
130#if ENABLE_BUNZIP2
131
132static 130static
133char* make_new_name_bunzip2(char *filename) 131char* make_new_name_generic(char *filename, const char *expected_ext)
134{ 132{
135 char *extension = strrchr(filename, '.'); 133 char *extension = strrchr(filename, '.');
136 if (!extension || strcmp(extension, ".bz2") != 0) { 134 if (!extension || strcmp(extension + 1, expected_ext) != 0) {
137 /* Mimic GNU gunzip - "real" bunzip2 tries to */ 135 /* Mimic GNU gunzip - "real" bunzip2 tries to */
138 /* unpack file anyway, to file.out */ 136 /* unpack file anyway, to file.out */
139 return NULL; 137 return NULL;
@@ -142,6 +140,14 @@ char* make_new_name_bunzip2(char *filename)
142 return filename; 140 return filename;
143} 141}
144 142
143#if ENABLE_BUNZIP2
144
145static
146char* make_new_name_bunzip2(char *filename)
147{
148 return make_new_name_generic(filename, "bz2");
149}
150
145static 151static
146USE_DESKTOP(long long) int unpack_bunzip2(void) 152USE_DESKTOP(long long) int unpack_bunzip2(void)
147{ 153{
@@ -200,13 +206,14 @@ char* make_new_name_gunzip(char *filename)
200 if (!extension) 206 if (!extension)
201 return NULL; 207 return NULL;
202 208
203 if (strcmp(extension, ".gz") == 0 209 extension++;
210 if (strcmp(extension, "tgz" + 1) == 0
204#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS 211#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
205 || strcmp(extension, ".Z") == 0 212 || strcmp(extension, "Z") == 0
206#endif 213#endif
207 ) { 214 ) {
208 *extension = '\0'; 215 extension[-1] = '\0';
209 } else if(strcmp(extension, ".tgz") == 0) { 216 } else if(strcmp(extension, "tgz") == 0) {
210 filename = xstrdup(filename); 217 filename = xstrdup(filename);
211 extension = strrchr(filename, '.'); 218 extension = strrchr(filename, '.');
212 extension[2] = 'a'; 219 extension[2] = 'a';
@@ -275,11 +282,7 @@ int gunzip_main(int argc, char **argv)
275static 282static
276char* make_new_name_unlzma(char *filename) 283char* make_new_name_unlzma(char *filename)
277{ 284{
278 char *extension = strrchr(filename, '.'); 285 return make_new_name_generic(filename, "lzma");
279 if (!extension || strcmp(extension, ".lzma") != 0)
280 return NULL;
281 *extension = '\0';
282 return filename;
283} 286}
284 287
285static 288static
@@ -315,11 +318,7 @@ int unlzma_main(int argc, char **argv)
315static 318static
316char* make_new_name_uncompress(char *filename) 319char* make_new_name_uncompress(char *filename)
317{ 320{
318 char *extension = strrchr(filename, '.'); 321 return make_new_name_generic(filename, "Z");
319 if (!extension || strcmp(extension, ".Z") != 0)
320 return NULL;
321 *extension = '\0';
322 return filename;
323} 322}
324 323
325static 324static