Make uncompress a seperate applet so it doesnt pull in all the gunzip code
authorGlenn L McGrath <bug1@ihug.co.nz>
Fri, 1 Nov 2002 23:38:54 +0000 (23:38 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Fri, 1 Nov 2002 23:38:54 +0000 (23:38 -0000)
archival/Makefile.in
archival/config.in
archival/gunzip.c
archival/libunarchive/decompress_uncompress.c
archival/libunarchive/uncompress.c
archival/uncompress.c [new file with mode: 0644]
include/applets.h
include/usage.h
sysdeps/linux/config.in

index c53171eea9287eba934c6627c7b6a2b5891761ce..226cde69017922dfdae009976ede2427083aaa05 100644 (file)
@@ -23,6 +23,7 @@ ARCHIVAL_DIR:=$(TOPDIR)archival/
 endif
 
 ARCHIVAL-y:=
+ARCHIVAL-$(CONFIG_APT_GET)     +=
 ARCHIVAL-$(CONFIG_AR)          += ar.o
 ARCHIVAL-$(CONFIG_BUNZIP2)     += bunzip2.o
 ARCHIVAL-$(CONFIG_CPIO)                += cpio.o
@@ -32,6 +33,7 @@ ARCHIVAL-$(CONFIG_GUNZIP)     += gunzip.o
 ARCHIVAL-$(CONFIG_GZIP)                += gzip.o
 ARCHIVAL-$(CONFIG_RPM2CPIO)    += rpm2cpio.o
 ARCHIVAL-$(CONFIG_TAR)         += tar.o
+ARCHIVAL-$(CONFIG_UNCOMPRESS)  += uncompress.o
 ARCHIVAL-$(CONFIG_UNZIP)       += unzip.o
 
 libraries-y+=$(ARCHIVAL_DIR)$(ARCHIVAL_AR)
index dd97909f9eee1a74bf0a7780d24fe1bc6d3a243a..689561b8e6426359c3aca4cb5789ff8c3675367e 100644 (file)
@@ -18,6 +18,9 @@ if [ "$CONFIG_DPKG_DEB" = "y" ] ; then
     bool '  -x support only'   CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY
 fi
 bool 'gunzip'      CONFIG_GUNZIP
+if [ "$CONFIG_GUNZIP" = "y" ]; then
+    bool '  Uncompress support'                CONFIG_FEATURE_GUNZIP_UNCOMPRESS
+fi
 bool 'gzip'        CONFIG_GZIP
 bool 'rpm2cpio'     CONFIG_RPM2CPIO
 bool 'tar'         CONFIG_TAR
@@ -31,5 +34,6 @@ fi
 if [ "$CONFIG_CPIO" = "y" -o "$CONFIG_TAR" = "y" ] ; then
     bool '  Enable tape drive support' CONFIG_FEATURE_UNARCHIVE_TAPE
 fi
+bool 'uncompress'   CONFIG_UNCOMPRESS
 bool 'unzip'       CONFIG_UNZIP
 endmenu
index b6f3e08ea578da89e568ac2b00e5a982a5c12bd4..e9963a8d23fa40592efd32c8c846497874d2151a 100644 (file)
@@ -143,7 +143,7 @@ extern int gunzip_main(int argc, char **argv)
                        new_path = xstrdup(old_path);
 
                        extension = strrchr(new_path, '.');
-#ifdef CONFIG_FEATURE_UNCOMPRESS
+#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
                        if (extension && (strcmp(extension, ".Z") == 0)) {
                                *extension = '\0';
                        } else
@@ -172,7 +172,7 @@ extern int gunzip_main(int argc, char **argv)
                        unsigned char magic2;
                        
                        magic2 = xread_char(src_fd);
-#ifdef CONFIG_FEATURE_UNCOMPRESS
+#ifdef CONFIG_FEATURE_GUNZIP_UNCOMPRESS
                        if (magic2 == 0x9d) {
                                status = uncompress(src_fd, dst_fd);
                        } else 
index 02835cfce67cb3f4fc59bb85374f2f09a14b30df..302201fc09d04a390f55ee137648714d7cbdd505 100644 (file)
@@ -1,7 +1,7 @@
 #include "config.h"
 #include "libbb.h"
 
-#ifdef CONFIG_FEATURE_UNCOMPRESS
+#ifdef CONFIG_UNCOMPRESS || defined CONFIG_FEATURE_GUNZIP_UNCOMPRESS
 
 /* uncompress for busybox -- (c) 2002 Robert Griebl
  *
index 02835cfce67cb3f4fc59bb85374f2f09a14b30df..302201fc09d04a390f55ee137648714d7cbdd505 100644 (file)
@@ -1,7 +1,7 @@
 #include "config.h"
 #include "libbb.h"
 
-#ifdef CONFIG_FEATURE_UNCOMPRESS
+#ifdef CONFIG_UNCOMPRESS || defined CONFIG_FEATURE_GUNZIP_UNCOMPRESS
 
 /* uncompress for busybox -- (c) 2002 Robert Griebl
  *
diff --git a/archival/uncompress.c b/archival/uncompress.c
new file mode 100644 (file)
index 0000000..877bcc7
--- /dev/null
@@ -0,0 +1,133 @@
+/* vi: set sw=4 ts=4: */
+/*
+ *     Uncompress applet for busybox (c) 2002 Glenn McGrath
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include "libbb.h"
+#include "unarchive.h"
+
+int uncompress_main(int argc, char **argv)
+{
+       const char gunzip_to_stdout = 1;
+       const char gunzip_force = 2;
+       char status = EXIT_SUCCESS;
+       char flags = 0;
+       int opt;
+
+       while ((opt = getopt(argc, argv, "cfh")) != -1) {
+               switch (opt) {
+               case 'c':
+                       flags |= gunzip_to_stdout;
+                       break;
+               case 'f':
+                       flags |= gunzip_force;
+                       break;
+               default:
+                       show_usage();   /* exit's inside usage */
+               }
+       }
+
+       do {
+               struct stat stat_buf;
+               const char *old_path = argv[optind];
+               const char *delete_path = NULL;
+               char *new_path = NULL;
+               int src_fd;
+               int dst_fd;
+
+               optind++;
+
+               if (old_path == NULL || strcmp(old_path, "-") == 0) {
+                       src_fd = fileno(stdin);
+                       flags |= gunzip_to_stdout;
+               } else {
+                       src_fd = xopen(old_path, O_RDONLY);
+
+                       /* Get the time stamp on the input file. */
+                       if (stat(old_path, &stat_buf) < 0) {
+                               error_msg_and_die("Couldn't stat file %s", old_path);
+                       }
+               }
+
+               /* Check that the input is sane.  */
+               if (isatty(src_fd) && ((flags & gunzip_force) == 0)) {
+                       error_msg_and_die
+                               ("compressed data not read from terminal.  Use -f to force it.");
+               }
+
+               /* Set output filename and number */
+               if (flags & gunzip_to_stdout) {
+                       dst_fd = fileno(stdout);
+               } else {
+                       char *extension;
+
+                       new_path = xstrdup(old_path);
+
+                       extension = strrchr(new_path, '.');
+                       if (!extension || (strcmp(extension, ".Z") != 0)) {
+                               error_msg_and_die("Invalid extension");
+                       }
+                       *extension = '\0';
+
+                       /* Open output file */
+                       dst_fd = xopen(new_path, O_WRONLY | O_CREAT);
+
+                       /* Set permissions on the file */
+                       chmod(new_path, stat_buf.st_mode);
+
+                       /* If unzip succeeds remove the old file */
+                       delete_path = old_path;
+               }
+
+               /* do the decompression, and cleanup */
+               if ((xread_char(src_fd) == 0x1f) && (xread_char(src_fd) == 0x9d)) {
+                       status = uncompress(src_fd, dst_fd);
+               } else {
+                       error_msg_and_die("Invalid magic");
+               }
+
+               if ((status != EXIT_SUCCESS) && (new_path)) {
+                       /* Unzip failed, remove new path instead of old path */
+                       delete_path = new_path;
+               }
+
+               if (dst_fd != fileno(stdout)) {
+                       close(dst_fd);
+               }
+               if (src_fd != fileno(stdin)) {
+                       close(src_fd);
+               }
+
+               /* delete_path will be NULL if in test mode or from stdin */
+               if (delete_path && (unlink(delete_path) == -1)) {
+                       error_msg_and_die("Couldn't remove %s", delete_path);
+               }
+
+               free(new_path);
+
+       } while (optind < argc);
+
+       return status;
+}
index 836ed99563cbf52713d072a54e55acfb0e2f7778..1660b11c54c051d5d114f2bdc7c53cfc75fa1849 100644 (file)
 #ifdef CONFIG_UNAME
        APPLET(uname, uname_main, _BB_DIR_BIN, _BB_SUID_NEVER)
 #endif
-#ifdef CONFIG_GUNZIP   
-# ifdef CONFIG_FEATURE_UNCOMPRESS
-       APPLET_ODDNAME("uncompress", gunzip_main, _BB_DIR_BIN, _BB_SUID_NEVER, gunzip)
-# endif
+#ifdef CONFIG_UNCOMPRESS
+       APPLET(uncompress, uncompress_main, _BB_DIR_BIN, _BB_SUID_NEVER)
 #endif
 #ifdef CONFIG_UNIQ
        APPLET(uniq, uniq_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)
index fb126a007b71b5fa1952a30f952b71c9b5769a33..8ea8c5a92057970a763b66d719ccf16b58a2e975 100644 (file)
        "$ uname -a\n" \
        "Linux debian 2.2.15pre13 #5 Tue Mar 14 16:03:50 MST 2000 i686 unknown\n" 
 
+#define uncompress_trivial_usage \
+       "[-c] [-f] [ name ... ]"
+#define uncompress_full_usage \
+       "Uncompress .Z file[s]\n" \
+       "Options:\n" \
+       "\t-c\textract to stdout\n" \
+       "\t-f\tforce overwrite an existing file\n"
+       
 #define uniq_trivial_usage \
        "[OPTION]... [INPUT [OUTPUT]]"
 #define uniq_full_usage \
index c1860556d2f92bc2c657551704c8c7b0c033c2be..ca7d97d4b47a2b397e75142e870940963d227feb 100644 (file)
@@ -14,7 +14,6 @@ bool 'Show verbose applet usage messages'                             CONFIG_FEATURE_VERBOSE_USAGE
 bool 'Support --install [-s] to install applet links at runtime'       CONFIG_FEATURE_INSTALLER
 bool 'Enable locale support (system needs locale for this to work)'    CONFIG_LOCALE_SUPPORT
 bool 'Support for devfs'                                               CONFIG_FEATURE_DEVFS
-bool 'Support compress format (.Z) in unzip operations'                CONFIG_FEATURE_UNCOMPRESS 
 bool 'Clean up all memory before exiting (usually not needed)'         CONFIG_FEATURE_CLEAN_UP
 bool 'Support for SUID/SGID handling'                                          CONFIG_FEATURE_SUID
 if [ "$CONFIG_FEATURE_SUID" = "y" ]; then