bbunzip: size optimization: ~90 bytes
diff --git a/archival/Kbuild b/archival/Kbuild
index 50b90fa..011feee 100644
--- a/archival/Kbuild
+++ b/archival/Kbuild
@@ -8,15 +8,15 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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