svn commit: trunk/busybox/archival

vda at busybox.net vda at busybox.net
Fri Mar 9 20:49:55 UTC 2007


Author: vda
Date: 2007-03-09 12:49:55 -0800 (Fri, 09 Mar 2007)
New Revision: 18057

Log:
bbunzip: size optimization: ~90 bytes


Modified:
   trunk/busybox/archival/Kbuild
   trunk/busybox/archival/bbunzip.c


Changeset:
Modified: trunk/busybox/archival/Kbuild
===================================================================
--- trunk/busybox/archival/Kbuild	2007-03-09 16:56:57 UTC (rev 18056)
+++ trunk/busybox/archival/Kbuild	2007-03-09 20:49:55 UTC (rev 18057)
@@ -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

Modified: trunk/busybox/archival/bbunzip.c
===================================================================
--- trunk/busybox/archival/bbunzip.c	2007-03-09 16:56:57 UTC (rev 18056)
+++ trunk/busybox/archival/bbunzip.c	2007-03-09 20:49:55 UTC (rev 18057)
@@ -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,7 +140,15 @@
 	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)
 {
 	return uncompressStream(STDIN_FILENO, STDOUT_FILENO);
@@ -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




More information about the busybox-cvs mailing list