diff options
| author | Glenn L McGrath <bug1@ihug.co.nz> | 2002-11-01 23:38:54 +0000 |
|---|---|---|
| committer | Glenn L McGrath <bug1@ihug.co.nz> | 2002-11-01 23:38:54 +0000 |
| commit | bf1cc8b1b7a218a4c2f4bfb23ea44c74b65ebbf6 (patch) | |
| tree | 4f0dbf581511eaaa3f0f86878f7e693a9faac6ce | |
| parent | d6aec8619d1713f90dba9999fa8dc52976aad1bd (diff) | |
| download | busybox-w32-bf1cc8b1b7a218a4c2f4bfb23ea44c74b65ebbf6.tar.gz busybox-w32-bf1cc8b1b7a218a4c2f4bfb23ea44c74b65ebbf6.tar.bz2 busybox-w32-bf1cc8b1b7a218a4c2f4bfb23ea44c74b65ebbf6.zip | |
Make uncompress a seperate applet so it doesnt pull in all the gunzip code
| -rw-r--r-- | archival/Makefile.in | 2 | ||||
| -rw-r--r-- | archival/config.in | 4 | ||||
| -rw-r--r-- | archival/gunzip.c | 4 | ||||
| -rw-r--r-- | archival/libunarchive/decompress_uncompress.c | 2 | ||||
| -rw-r--r-- | archival/libunarchive/uncompress.c | 2 | ||||
| -rw-r--r-- | archival/uncompress.c | 133 | ||||
| -rw-r--r-- | include/applets.h | 6 | ||||
| -rw-r--r-- | include/usage.h | 8 | ||||
| -rw-r--r-- | sysdeps/linux/config.in | 1 |
9 files changed, 153 insertions, 9 deletions
diff --git a/archival/Makefile.in b/archival/Makefile.in index c53171eea..226cde690 100644 --- a/archival/Makefile.in +++ b/archival/Makefile.in | |||
| @@ -23,6 +23,7 @@ ARCHIVAL_DIR:=$(TOPDIR)archival/ | |||
| 23 | endif | 23 | endif |
| 24 | 24 | ||
| 25 | ARCHIVAL-y:= | 25 | ARCHIVAL-y:= |
| 26 | ARCHIVAL-$(CONFIG_APT_GET) += | ||
| 26 | ARCHIVAL-$(CONFIG_AR) += ar.o | 27 | ARCHIVAL-$(CONFIG_AR) += ar.o |
| 27 | ARCHIVAL-$(CONFIG_BUNZIP2) += bunzip2.o | 28 | ARCHIVAL-$(CONFIG_BUNZIP2) += bunzip2.o |
| 28 | ARCHIVAL-$(CONFIG_CPIO) += cpio.o | 29 | ARCHIVAL-$(CONFIG_CPIO) += cpio.o |
| @@ -32,6 +33,7 @@ ARCHIVAL-$(CONFIG_GUNZIP) += gunzip.o | |||
| 32 | ARCHIVAL-$(CONFIG_GZIP) += gzip.o | 33 | ARCHIVAL-$(CONFIG_GZIP) += gzip.o |
| 33 | ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o | 34 | ARCHIVAL-$(CONFIG_RPM2CPIO) += rpm2cpio.o |
| 34 | ARCHIVAL-$(CONFIG_TAR) += tar.o | 35 | ARCHIVAL-$(CONFIG_TAR) += tar.o |
| 36 | ARCHIVAL-$(CONFIG_UNCOMPRESS) += uncompress.o | ||
| 35 | ARCHIVAL-$(CONFIG_UNZIP) += unzip.o | 37 | ARCHIVAL-$(CONFIG_UNZIP) += unzip.o |
| 36 | 38 | ||
| 37 | libraries-y+=$(ARCHIVAL_DIR)$(ARCHIVAL_AR) | 39 | libraries-y+=$(ARCHIVAL_DIR)$(ARCHIVAL_AR) |
diff --git a/archival/config.in b/archival/config.in index dd97909f9..689561b8e 100644 --- a/archival/config.in +++ b/archival/config.in | |||
| @@ -18,6 +18,9 @@ if [ "$CONFIG_DPKG_DEB" = "y" ] ; then | |||
| 18 | bool ' -x support only' CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY | 18 | bool ' -x support only' CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY |
| 19 | fi | 19 | fi |
| 20 | bool 'gunzip' CONFIG_GUNZIP | 20 | bool 'gunzip' CONFIG_GUNZIP |
| 21 | if [ "$CONFIG_GUNZIP" = "y" ]; then | ||
| 22 | bool ' Uncompress support' CONFIG_FEATURE_GUNZIP_UNCOMPRESS | ||
| 23 | fi | ||
| 21 | bool 'gzip' CONFIG_GZIP | 24 | bool 'gzip' CONFIG_GZIP |
| 22 | bool 'rpm2cpio' CONFIG_RPM2CPIO | 25 | bool 'rpm2cpio' CONFIG_RPM2CPIO |
| 23 | bool 'tar' CONFIG_TAR | 26 | bool 'tar' CONFIG_TAR |
| @@ -31,5 +34,6 @@ fi | |||
| 31 | if [ "$CONFIG_CPIO" = "y" -o "$CONFIG_TAR" = "y" ] ; then | 34 | if [ "$CONFIG_CPIO" = "y" -o "$CONFIG_TAR" = "y" ] ; then |
| 32 | bool ' Enable tape drive support' CONFIG_FEATURE_UNARCHIVE_TAPE | 35 | bool ' Enable tape drive support' CONFIG_FEATURE_UNARCHIVE_TAPE |
| 33 | fi | 36 | fi |
| 37 | bool 'uncompress' CONFIG_UNCOMPRESS | ||
| 34 | bool 'unzip' CONFIG_UNZIP | 38 | bool 'unzip' CONFIG_UNZIP |
| 35 | endmenu | 39 | endmenu |
diff --git a/archival/gunzip.c b/archival/gunzip.c index b6f3e08ea..e9963a8d2 100644 --- a/archival/gunzip.c +++ b/archival/gunzip.c | |||
| @@ -143,7 +143,7 @@ extern int gunzip_main(int argc, char **argv) | |||
| 143 | new_path = xstrdup(old_path); | 143 | new_path = xstrdup(old_path); |
| 144 | 144 | ||
| 145 | extension = strrchr(new_path, '.'); | 145 | extension = strrchr(new_path, '.'); |
| 146 | #ifdef CONFIG_FEATURE_UNCOMPRESS | 146 | #ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS |
| 147 | if (extension && (strcmp(extension, ".Z") == 0)) { | 147 | if (extension && (strcmp(extension, ".Z") == 0)) { |
| 148 | *extension = '\0'; | 148 | *extension = '\0'; |
| 149 | } else | 149 | } else |
| @@ -172,7 +172,7 @@ extern int gunzip_main(int argc, char **argv) | |||
| 172 | unsigned char magic2; | 172 | unsigned char magic2; |
| 173 | 173 | ||
| 174 | magic2 = xread_char(src_fd); | 174 | magic2 = xread_char(src_fd); |
| 175 | #ifdef CONFIG_FEATURE_UNCOMPRESS | 175 | #ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS |
| 176 | if (magic2 == 0x9d) { | 176 | if (magic2 == 0x9d) { |
| 177 | status = uncompress(src_fd, dst_fd); | 177 | status = uncompress(src_fd, dst_fd); |
| 178 | } else | 178 | } else |
diff --git a/archival/libunarchive/decompress_uncompress.c b/archival/libunarchive/decompress_uncompress.c index 02835cfce..302201fc0 100644 --- a/archival/libunarchive/decompress_uncompress.c +++ b/archival/libunarchive/decompress_uncompress.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #include "config.h" | 1 | #include "config.h" |
| 2 | #include "libbb.h" | 2 | #include "libbb.h" |
| 3 | 3 | ||
| 4 | #ifdef CONFIG_FEATURE_UNCOMPRESS | 4 | #ifdef CONFIG_UNCOMPRESS || defined CONFIG_FEATURE_GUNZIP_UNCOMPRESS |
| 5 | 5 | ||
| 6 | /* uncompress for busybox -- (c) 2002 Robert Griebl | 6 | /* uncompress for busybox -- (c) 2002 Robert Griebl |
| 7 | * | 7 | * |
diff --git a/archival/libunarchive/uncompress.c b/archival/libunarchive/uncompress.c index 02835cfce..302201fc0 100644 --- a/archival/libunarchive/uncompress.c +++ b/archival/libunarchive/uncompress.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #include "config.h" | 1 | #include "config.h" |
| 2 | #include "libbb.h" | 2 | #include "libbb.h" |
| 3 | 3 | ||
| 4 | #ifdef CONFIG_FEATURE_UNCOMPRESS | 4 | #ifdef CONFIG_UNCOMPRESS || defined CONFIG_FEATURE_GUNZIP_UNCOMPRESS |
| 5 | 5 | ||
| 6 | /* uncompress for busybox -- (c) 2002 Robert Griebl | 6 | /* uncompress for busybox -- (c) 2002 Robert Griebl |
| 7 | * | 7 | * |
diff --git a/archival/uncompress.c b/archival/uncompress.c new file mode 100644 index 000000000..877bcc784 --- /dev/null +++ b/archival/uncompress.c | |||
| @@ -0,0 +1,133 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Uncompress applet for busybox (c) 2002 Glenn McGrath | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <stdlib.h> | ||
| 21 | #include <string.h> | ||
| 22 | #include <unistd.h> | ||
| 23 | #include <getopt.h> | ||
| 24 | #include <sys/types.h> | ||
| 25 | #include <sys/stat.h> | ||
| 26 | #include <fcntl.h> | ||
| 27 | |||
| 28 | #include "libbb.h" | ||
| 29 | #include "unarchive.h" | ||
| 30 | |||
| 31 | int uncompress_main(int argc, char **argv) | ||
| 32 | { | ||
| 33 | const char gunzip_to_stdout = 1; | ||
| 34 | const char gunzip_force = 2; | ||
| 35 | char status = EXIT_SUCCESS; | ||
| 36 | char flags = 0; | ||
| 37 | int opt; | ||
| 38 | |||
| 39 | while ((opt = getopt(argc, argv, "cfh")) != -1) { | ||
| 40 | switch (opt) { | ||
| 41 | case 'c': | ||
| 42 | flags |= gunzip_to_stdout; | ||
| 43 | break; | ||
| 44 | case 'f': | ||
| 45 | flags |= gunzip_force; | ||
| 46 | break; | ||
| 47 | default: | ||
| 48 | show_usage(); /* exit's inside usage */ | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | do { | ||
| 53 | struct stat stat_buf; | ||
| 54 | const char *old_path = argv[optind]; | ||
| 55 | const char *delete_path = NULL; | ||
| 56 | char *new_path = NULL; | ||
| 57 | int src_fd; | ||
| 58 | int dst_fd; | ||
| 59 | |||
| 60 | optind++; | ||
| 61 | |||
| 62 | if (old_path == NULL || strcmp(old_path, "-") == 0) { | ||
| 63 | src_fd = fileno(stdin); | ||
| 64 | flags |= gunzip_to_stdout; | ||
| 65 | } else { | ||
| 66 | src_fd = xopen(old_path, O_RDONLY); | ||
| 67 | |||
| 68 | /* Get the time stamp on the input file. */ | ||
| 69 | if (stat(old_path, &stat_buf) < 0) { | ||
| 70 | error_msg_and_die("Couldn't stat file %s", old_path); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | /* Check that the input is sane. */ | ||
| 75 | if (isatty(src_fd) && ((flags & gunzip_force) == 0)) { | ||
| 76 | error_msg_and_die | ||
| 77 | ("compressed data not read from terminal. Use -f to force it."); | ||
| 78 | } | ||
| 79 | |||
| 80 | /* Set output filename and number */ | ||
| 81 | if (flags & gunzip_to_stdout) { | ||
| 82 | dst_fd = fileno(stdout); | ||
| 83 | } else { | ||
| 84 | char *extension; | ||
| 85 | |||
| 86 | new_path = xstrdup(old_path); | ||
| 87 | |||
| 88 | extension = strrchr(new_path, '.'); | ||
| 89 | if (!extension || (strcmp(extension, ".Z") != 0)) { | ||
| 90 | error_msg_and_die("Invalid extension"); | ||
| 91 | } | ||
| 92 | *extension = '\0'; | ||
| 93 | |||
| 94 | /* Open output file */ | ||
| 95 | dst_fd = xopen(new_path, O_WRONLY | O_CREAT); | ||
| 96 | |||
| 97 | /* Set permissions on the file */ | ||
| 98 | chmod(new_path, stat_buf.st_mode); | ||
| 99 | |||
| 100 | /* If unzip succeeds remove the old file */ | ||
| 101 | delete_path = old_path; | ||
| 102 | } | ||
| 103 | |||
| 104 | /* do the decompression, and cleanup */ | ||
| 105 | if ((xread_char(src_fd) == 0x1f) && (xread_char(src_fd) == 0x9d)) { | ||
| 106 | status = uncompress(src_fd, dst_fd); | ||
| 107 | } else { | ||
| 108 | error_msg_and_die("Invalid magic"); | ||
| 109 | } | ||
| 110 | |||
| 111 | if ((status != EXIT_SUCCESS) && (new_path)) { | ||
| 112 | /* Unzip failed, remove new path instead of old path */ | ||
| 113 | delete_path = new_path; | ||
| 114 | } | ||
| 115 | |||
| 116 | if (dst_fd != fileno(stdout)) { | ||
| 117 | close(dst_fd); | ||
| 118 | } | ||
| 119 | if (src_fd != fileno(stdin)) { | ||
| 120 | close(src_fd); | ||
| 121 | } | ||
| 122 | |||
| 123 | /* delete_path will be NULL if in test mode or from stdin */ | ||
| 124 | if (delete_path && (unlink(delete_path) == -1)) { | ||
| 125 | error_msg_and_die("Couldn't remove %s", delete_path); | ||
| 126 | } | ||
| 127 | |||
| 128 | free(new_path); | ||
| 129 | |||
| 130 | } while (optind < argc); | ||
| 131 | |||
| 132 | return status; | ||
| 133 | } | ||
diff --git a/include/applets.h b/include/applets.h index 836ed9956..1660b11c5 100644 --- a/include/applets.h +++ b/include/applets.h | |||
| @@ -515,10 +515,8 @@ | |||
| 515 | #ifdef CONFIG_UNAME | 515 | #ifdef CONFIG_UNAME |
| 516 | APPLET(uname, uname_main, _BB_DIR_BIN, _BB_SUID_NEVER) | 516 | APPLET(uname, uname_main, _BB_DIR_BIN, _BB_SUID_NEVER) |
| 517 | #endif | 517 | #endif |
| 518 | #ifdef CONFIG_GUNZIP | 518 | #ifdef CONFIG_UNCOMPRESS |
| 519 | # ifdef CONFIG_FEATURE_UNCOMPRESS | 519 | APPLET(uncompress, uncompress_main, _BB_DIR_BIN, _BB_SUID_NEVER) |
| 520 | APPLET_ODDNAME("uncompress", gunzip_main, _BB_DIR_BIN, _BB_SUID_NEVER, gunzip) | ||
| 521 | # endif | ||
| 522 | #endif | 520 | #endif |
| 523 | #ifdef CONFIG_UNIQ | 521 | #ifdef CONFIG_UNIQ |
| 524 | APPLET(uniq, uniq_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) | 522 | APPLET(uniq, uniq_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) |
diff --git a/include/usage.h b/include/usage.h index fb126a007..8ea8c5a92 100644 --- a/include/usage.h +++ b/include/usage.h | |||
| @@ -2032,6 +2032,14 @@ | |||
| 2032 | "$ uname -a\n" \ | 2032 | "$ uname -a\n" \ |
| 2033 | "Linux debian 2.2.15pre13 #5 Tue Mar 14 16:03:50 MST 2000 i686 unknown\n" | 2033 | "Linux debian 2.2.15pre13 #5 Tue Mar 14 16:03:50 MST 2000 i686 unknown\n" |
| 2034 | 2034 | ||
| 2035 | #define uncompress_trivial_usage \ | ||
| 2036 | "[-c] [-f] [ name ... ]" | ||
| 2037 | #define uncompress_full_usage \ | ||
| 2038 | "Uncompress .Z file[s]\n" \ | ||
| 2039 | "Options:\n" \ | ||
| 2040 | "\t-c\textract to stdout\n" \ | ||
| 2041 | "\t-f\tforce overwrite an existing file\n" | ||
| 2042 | |||
| 2035 | #define uniq_trivial_usage \ | 2043 | #define uniq_trivial_usage \ |
| 2036 | "[OPTION]... [INPUT [OUTPUT]]" | 2044 | "[OPTION]... [INPUT [OUTPUT]]" |
| 2037 | #define uniq_full_usage \ | 2045 | #define uniq_full_usage \ |
diff --git a/sysdeps/linux/config.in b/sysdeps/linux/config.in index c1860556d..ca7d97d4b 100644 --- a/sysdeps/linux/config.in +++ b/sysdeps/linux/config.in | |||
| @@ -14,7 +14,6 @@ bool 'Show verbose applet usage messages' CONFIG_FEATURE_VERBOSE_USAGE | |||
| 14 | bool 'Support --install [-s] to install applet links at runtime' CONFIG_FEATURE_INSTALLER | 14 | bool 'Support --install [-s] to install applet links at runtime' CONFIG_FEATURE_INSTALLER |
| 15 | bool 'Enable locale support (system needs locale for this to work)' CONFIG_LOCALE_SUPPORT | 15 | bool 'Enable locale support (system needs locale for this to work)' CONFIG_LOCALE_SUPPORT |
| 16 | bool 'Support for devfs' CONFIG_FEATURE_DEVFS | 16 | bool 'Support for devfs' CONFIG_FEATURE_DEVFS |
| 17 | bool 'Support compress format (.Z) in unzip operations' CONFIG_FEATURE_UNCOMPRESS | ||
| 18 | bool 'Clean up all memory before exiting (usually not needed)' CONFIG_FEATURE_CLEAN_UP | 17 | bool 'Clean up all memory before exiting (usually not needed)' CONFIG_FEATURE_CLEAN_UP |
| 19 | bool 'Support for SUID/SGID handling' CONFIG_FEATURE_SUID | 18 | bool 'Support for SUID/SGID handling' CONFIG_FEATURE_SUID |
| 20 | if [ "$CONFIG_FEATURE_SUID" = "y" ]; then | 19 | if [ "$CONFIG_FEATURE_SUID" = "y" ]; then |
