From: Denis Vlasenko Date: Fri, 9 Mar 2007 20:49:55 +0000 (-0000) Subject: bbunzip: size optimization: ~90 bytes X-Git-Tag: 1_5_1~87 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=bebbd8c9baaa7a2da5ac9ab484f54ce3115982d5;p=oweals%2Fbusybox.git bbunzip: size optimization: ~90 bytes --- diff --git a/archival/Kbuild b/archival/Kbuild index 50b90fa93..011feee5f 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 3dff946a1..b922fd373 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