summaryrefslogtreecommitdiff
path: root/archival/bbunzip.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-03-09 20:49:55 +0000
committerDenis Vlasenko2007-03-09 20:49:55 +0000
commitbebbd8c9baaa7a2da5ac9ab484f54ce3115982d5 (patch)
tree14bbc1d2a6a996403bc823be203a2283caf0d95f /archival/bbunzip.c
parentf25d57e0b40efbd5dcb4ccd38a9c9f054faa9446 (diff)
downloadbusybox-bebbd8c9baaa7a2da5ac9ab484f54ce3115982d5.zip
busybox-bebbd8c9baaa7a2da5ac9ab484f54ce3115982d5.tar.gz
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 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