diff options
author | Denis Vlasenko | 2007-03-09 20:49:55 +0000 |
---|---|---|
committer | Denis Vlasenko | 2007-03-09 20:49:55 +0000 |
commit | bebbd8c9baaa7a2da5ac9ab484f54ce3115982d5 (patch) | |
tree | 14bbc1d2a6a996403bc823be203a2283caf0d95f /archival | |
parent | f25d57e0b40efbd5dcb4ccd38a9c9f054faa9446 (diff) | |
download | busybox-bebbd8c9baaa7a2da5ac9ab484f54ce3115982d5.zip busybox-bebbd8c9baaa7a2da5ac9ab484f54ce3115982d5.tar.gz |
bbunzip: size optimization: ~90 bytes
Diffstat (limited to 'archival')
-rw-r--r-- | archival/Kbuild | 8 | ||||
-rw-r--r-- | archival/bbunzip.c | 35 |
2 files changed, 21 insertions, 22 deletions
diff --git a/archival/Kbuild b/archival/Kbuild index 50b90fa..011feee 100644 --- a/archival/Kbuild +++ b/archival/Kbuild @@ -8,15 +8,15 @@ libs-y += libunarchive/ lib-y:= lib-$(CONFIG_AR) += ar.o -lib-$(CONFIG_BUNZIP2) += bbunzip.o ### bunzip2.o -lib-$(CONFIG_UNLZMA) += bbunzip.o ### unlzma.o +lib-$(CONFIG_BUNZIP2) += bbunzip.o +lib-$(CONFIG_UNLZMA) += bbunzip.o lib-$(CONFIG_CPIO) += cpio.o lib-$(CONFIG_DPKG) += dpkg.o lib-$(CONFIG_DPKG_DEB) += dpkg_deb.o -lib-$(CONFIG_GUNZIP) += bbunzip.o ### gunzip.o +lib-$(CONFIG_GUNZIP) += bbunzip.o lib-$(CONFIG_GZIP) += gzip.o lib-$(CONFIG_RPM2CPIO) += rpm2cpio.o lib-$(CONFIG_RPM) += rpm.o lib-$(CONFIG_TAR) += tar.o -lib-$(CONFIG_UNCOMPRESS) += bbunzip.o ### uncompress.o +lib-$(CONFIG_UNCOMPRESS) += bbunzip.o lib-$(CONFIG_UNZIP) += unzip.o diff --git a/archival/bbunzip.c b/archival/bbunzip.c index 3dff946..b922fd3 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c @@ -127,13 +127,11 @@ int unpack(char **argv, return exitcode; } -#if ENABLE_BUNZIP2 - static -char* make_new_name_bunzip2(char *filename) +char* make_new_name_generic(char *filename, const char *expected_ext) { char *extension = strrchr(filename, '.'); - if (!extension || strcmp(extension, ".bz2") != 0) { + if (!extension || strcmp(extension + 1, expected_ext) != 0) { /* Mimic GNU gunzip - "real" bunzip2 tries to */ /* unpack file anyway, to file.out */ return NULL; @@ -142,6 +140,14 @@ char* make_new_name_bunzip2(char *filename) return filename; } +#if ENABLE_BUNZIP2 + +static +char* make_new_name_bunzip2(char *filename) +{ + return make_new_name_generic(filename, "bz2"); +} + static USE_DESKTOP(long long) int unpack_bunzip2(void) { @@ -200,13 +206,14 @@ char* make_new_name_gunzip(char *filename) if (!extension) return NULL; - if (strcmp(extension, ".gz") == 0 + extension++; + if (strcmp(extension, "tgz" + 1) == 0 #ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS - || strcmp(extension, ".Z") == 0 + || strcmp(extension, "Z") == 0 #endif ) { - *extension = '\0'; - } else if(strcmp(extension, ".tgz") == 0) { + extension[-1] = '\0'; + } else if(strcmp(extension, "tgz") == 0) { filename = xstrdup(filename); extension = strrchr(filename, '.'); extension[2] = 'a'; @@ -275,11 +282,7 @@ int gunzip_main(int argc, char **argv) static char* make_new_name_unlzma(char *filename) { - char *extension = strrchr(filename, '.'); - if (!extension || strcmp(extension, ".lzma") != 0) - return NULL; - *extension = '\0'; - return filename; + return make_new_name_generic(filename, "lzma"); } static @@ -315,11 +318,7 @@ int unlzma_main(int argc, char **argv) static char* make_new_name_uncompress(char *filename) { - char *extension = strrchr(filename, '.'); - if (!extension || strcmp(extension, ".Z") != 0) - return NULL; - *extension = '\0'; - return filename; + return make_new_name_generic(filename, "Z"); } static |