diff options
| author | sandman <sandman@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2002-05-15 22:13:47 +0000 |
|---|---|---|
| committer | sandman <sandman@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2002-05-15 22:13:47 +0000 |
| commit | 1f7475e1780dee89eeba14bf1bf0db37757fd805 (patch) | |
| tree | a53533813c8dc4c953532a679fc34d6903e0c3a0 | |
| parent | e10335d680f1bf9d4794983008911dd8acfac45e (diff) | |
| download | busybox-w32-1f7475e1780dee89eeba14bf1bf0db37757fd805.tar.gz busybox-w32-1f7475e1780dee89eeba14bf1bf0db37757fd805.tar.bz2 busybox-w32-1f7475e1780dee89eeba14bf1bf0db37757fd805.zip | |
Support old-style compress (.Z) files via libbb / unzip( ) calls
(configurable) - When enabled an applet "uncompress" is also made
available (oddname to gunzip)
git-svn-id: svn://busybox.net/trunk/busybox@4778 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | archival/libunarchive/decompress_unzip.c | 18 | ||||
| -rw-r--r-- | archival/libunarchive/unzip.c | 18 | ||||
| -rw-r--r-- | include/applets.h | 5 | ||||
| -rw-r--r-- | libbb/Makefile.in | 2 | ||||
| -rw-r--r-- | libbb/unzip.c | 18 | ||||
| -rw-r--r-- | sysdeps/linux/config.in | 1 |
6 files changed, 58 insertions, 4 deletions
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c index 9f6ed2ebe..cde16d067 100644 --- a/archival/libunarchive/decompress_unzip.c +++ b/archival/libunarchive/decompress_unzip.c | |||
| @@ -65,8 +65,13 @@ static char *license_msg[] = { | |||
| 65 | #include <signal.h> | 65 | #include <signal.h> |
| 66 | #include <stdlib.h> | 66 | #include <stdlib.h> |
| 67 | #include <string.h> | 67 | #include <string.h> |
| 68 | #include "config.h" | ||
| 68 | #include "libbb.h" | 69 | #include "libbb.h" |
| 69 | 70 | ||
| 71 | #ifdef CONFIG_FEATURE_UNCOMPRESS | ||
| 72 | int uncompress ( FILE *in, FILE *out ); | ||
| 73 | #endif | ||
| 74 | |||
| 70 | static FILE *in_file, *out_file; | 75 | static FILE *in_file, *out_file; |
| 71 | 76 | ||
| 72 | /* these are freed by gz_close */ | 77 | /* these are freed by gz_close */ |
| @@ -911,6 +916,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) | |||
| 911 | unsigned char flags; /* compression flags */ | 916 | unsigned char flags; /* compression flags */ |
| 912 | typedef void (*sig_type) (int); | 917 | typedef void (*sig_type) (int); |
| 913 | unsigned short i; | 918 | unsigned short i; |
| 919 | unsigned char magic [2]; | ||
| 914 | 920 | ||
| 915 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) { | 921 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) { |
| 916 | (void) signal(SIGINT, (sig_type) abort_gzip); | 922 | (void) signal(SIGINT, (sig_type) abort_gzip); |
| @@ -926,8 +932,18 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) | |||
| 926 | } | 932 | } |
| 927 | #endif | 933 | #endif |
| 928 | 934 | ||
| 935 | magic [0] = fgetc(l_in_file); | ||
| 936 | magic [1] = fgetc(l_in_file); | ||
| 937 | |||
| 938 | #ifdef CONFIG_FEATURE_UNCOMPRESS | ||
| 939 | /* Magic header for compress files, 1F 9d = \037\235 */ | ||
| 940 | if (( magic [0] == 0x1F ) && ( magic [1] == 0x9d)) { | ||
| 941 | return uncompress ( l_in_file, l_out_file ); | ||
| 942 | } | ||
| 943 | #endif | ||
| 944 | |||
| 929 | /* Magic header for gzip files, 1F 8B = \037\213 */ | 945 | /* Magic header for gzip files, 1F 8B = \037\213 */ |
| 930 | if ((fgetc(l_in_file) != 0x1F) || (fgetc(l_in_file) != 0x8b)) { | 946 | if (( magic [0] != 0x1F ) || ( magic [1] != 0x8b)) { |
| 931 | error_msg("Invalid gzip magic"); | 947 | error_msg("Invalid gzip magic"); |
| 932 | return EXIT_FAILURE; | 948 | return EXIT_FAILURE; |
| 933 | } | 949 | } |
diff --git a/archival/libunarchive/unzip.c b/archival/libunarchive/unzip.c index 9f6ed2ebe..cde16d067 100644 --- a/archival/libunarchive/unzip.c +++ b/archival/libunarchive/unzip.c | |||
| @@ -65,8 +65,13 @@ static char *license_msg[] = { | |||
| 65 | #include <signal.h> | 65 | #include <signal.h> |
| 66 | #include <stdlib.h> | 66 | #include <stdlib.h> |
| 67 | #include <string.h> | 67 | #include <string.h> |
| 68 | #include "config.h" | ||
| 68 | #include "libbb.h" | 69 | #include "libbb.h" |
| 69 | 70 | ||
| 71 | #ifdef CONFIG_FEATURE_UNCOMPRESS | ||
| 72 | int uncompress ( FILE *in, FILE *out ); | ||
| 73 | #endif | ||
| 74 | |||
| 70 | static FILE *in_file, *out_file; | 75 | static FILE *in_file, *out_file; |
| 71 | 76 | ||
| 72 | /* these are freed by gz_close */ | 77 | /* these are freed by gz_close */ |
| @@ -911,6 +916,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) | |||
| 911 | unsigned char flags; /* compression flags */ | 916 | unsigned char flags; /* compression flags */ |
| 912 | typedef void (*sig_type) (int); | 917 | typedef void (*sig_type) (int); |
| 913 | unsigned short i; | 918 | unsigned short i; |
| 919 | unsigned char magic [2]; | ||
| 914 | 920 | ||
| 915 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) { | 921 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) { |
| 916 | (void) signal(SIGINT, (sig_type) abort_gzip); | 922 | (void) signal(SIGINT, (sig_type) abort_gzip); |
| @@ -926,8 +932,18 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) | |||
| 926 | } | 932 | } |
| 927 | #endif | 933 | #endif |
| 928 | 934 | ||
| 935 | magic [0] = fgetc(l_in_file); | ||
| 936 | magic [1] = fgetc(l_in_file); | ||
| 937 | |||
| 938 | #ifdef CONFIG_FEATURE_UNCOMPRESS | ||
| 939 | /* Magic header for compress files, 1F 9d = \037\235 */ | ||
| 940 | if (( magic [0] == 0x1F ) && ( magic [1] == 0x9d)) { | ||
| 941 | return uncompress ( l_in_file, l_out_file ); | ||
| 942 | } | ||
| 943 | #endif | ||
| 944 | |||
| 929 | /* Magic header for gzip files, 1F 8B = \037\213 */ | 945 | /* Magic header for gzip files, 1F 8B = \037\213 */ |
| 930 | if ((fgetc(l_in_file) != 0x1F) || (fgetc(l_in_file) != 0x8b)) { | 946 | if (( magic [0] != 0x1F ) || ( magic [1] != 0x8b)) { |
| 931 | error_msg("Invalid gzip magic"); | 947 | error_msg("Invalid gzip magic"); |
| 932 | return EXIT_FAILURE; | 948 | return EXIT_FAILURE; |
| 933 | } | 949 | } |
diff --git a/include/applets.h b/include/applets.h index aaac6a9d4..6d01901a3 100644 --- a/include/applets.h +++ b/include/applets.h | |||
| @@ -467,6 +467,11 @@ | |||
| 467 | #ifdef CONFIG_UNAME | 467 | #ifdef CONFIG_UNAME |
| 468 | APPLET(uname, uname_main, _BB_DIR_BIN) | 468 | APPLET(uname, uname_main, _BB_DIR_BIN) |
| 469 | #endif | 469 | #endif |
| 470 | #ifdef CONFIG_GUNZIP | ||
| 471 | # ifdef CONFIG_FEATURE_UNCOMPRESS | ||
| 472 | APPLET_ODDNAME("uncompress", gunzip_main, _BB_DIR_BIN, gunzip) | ||
| 473 | # endif | ||
| 474 | #endif | ||
| 470 | #ifdef CONFIG_UNIQ | 475 | #ifdef CONFIG_UNIQ |
| 471 | APPLET(uniq, uniq_main, _BB_DIR_USR_BIN) | 476 | APPLET(uniq, uniq_main, _BB_DIR_USR_BIN) |
| 472 | #endif | 477 | #endif |
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index 6d098c0e5..c6493bfa6 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
| @@ -34,7 +34,7 @@ LIBBB_SRC:= \ | |||
| 34 | my_getpwuid.c parse_mode.c parse_number.c perror_msg.c perror_msg_and_die.c \ | 34 | my_getpwuid.c parse_mode.c parse_number.c perror_msg.c perror_msg_and_die.c \ |
| 35 | print_file.c process_escape_sequence.c read_package_field.c recursive_action.c \ | 35 | print_file.c process_escape_sequence.c read_package_field.c recursive_action.c \ |
| 36 | safe_read.c safe_strncpy.c syscalls.c syslog_msg_with_name.c time_string.c \ | 36 | safe_read.c safe_strncpy.c syscalls.c syslog_msg_with_name.c time_string.c \ |
| 37 | trim.c unzip.c vdprintf.c verror_msg.c vperror_msg.c wfopen.c xfuncs.c \ | 37 | trim.c unzip.c uncompress.c vdprintf.c verror_msg.c vperror_msg.c wfopen.c xfuncs.c \ |
| 38 | xgetcwd.c xreadlink.c xregcomp.c interface.c remove_file.c last_char_is.c \ | 38 | xgetcwd.c xreadlink.c xregcomp.c interface.c remove_file.c last_char_is.c \ |
| 39 | copyfd.c vherror_msg.c herror_msg.c herror_msg_and_die.c xgethostbyname.c \ | 39 | copyfd.c vherror_msg.c herror_msg.c herror_msg_and_die.c xgethostbyname.c \ |
| 40 | dirname.c make_directory.c create_icmp_socket.c u_signal_names.c arith.c \ | 40 | dirname.c make_directory.c create_icmp_socket.c u_signal_names.c arith.c \ |
diff --git a/libbb/unzip.c b/libbb/unzip.c index 9f6ed2ebe..cde16d067 100644 --- a/libbb/unzip.c +++ b/libbb/unzip.c | |||
| @@ -65,8 +65,13 @@ static char *license_msg[] = { | |||
| 65 | #include <signal.h> | 65 | #include <signal.h> |
| 66 | #include <stdlib.h> | 66 | #include <stdlib.h> |
| 67 | #include <string.h> | 67 | #include <string.h> |
| 68 | #include "config.h" | ||
| 68 | #include "libbb.h" | 69 | #include "libbb.h" |
| 69 | 70 | ||
| 71 | #ifdef CONFIG_FEATURE_UNCOMPRESS | ||
| 72 | int uncompress ( FILE *in, FILE *out ); | ||
| 73 | #endif | ||
| 74 | |||
| 70 | static FILE *in_file, *out_file; | 75 | static FILE *in_file, *out_file; |
| 71 | 76 | ||
| 72 | /* these are freed by gz_close */ | 77 | /* these are freed by gz_close */ |
| @@ -911,6 +916,7 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) | |||
| 911 | unsigned char flags; /* compression flags */ | 916 | unsigned char flags; /* compression flags */ |
| 912 | typedef void (*sig_type) (int); | 917 | typedef void (*sig_type) (int); |
| 913 | unsigned short i; | 918 | unsigned short i; |
| 919 | unsigned char magic [2]; | ||
| 914 | 920 | ||
| 915 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) { | 921 | if (signal(SIGINT, SIG_IGN) != SIG_IGN) { |
| 916 | (void) signal(SIGINT, (sig_type) abort_gzip); | 922 | (void) signal(SIGINT, (sig_type) abort_gzip); |
| @@ -926,8 +932,18 @@ extern int unzip(FILE *l_in_file, FILE *l_out_file) | |||
| 926 | } | 932 | } |
| 927 | #endif | 933 | #endif |
| 928 | 934 | ||
| 935 | magic [0] = fgetc(l_in_file); | ||
| 936 | magic [1] = fgetc(l_in_file); | ||
| 937 | |||
| 938 | #ifdef CONFIG_FEATURE_UNCOMPRESS | ||
| 939 | /* Magic header for compress files, 1F 9d = \037\235 */ | ||
| 940 | if (( magic [0] == 0x1F ) && ( magic [1] == 0x9d)) { | ||
| 941 | return uncompress ( l_in_file, l_out_file ); | ||
| 942 | } | ||
| 943 | #endif | ||
| 944 | |||
| 929 | /* Magic header for gzip files, 1F 8B = \037\213 */ | 945 | /* Magic header for gzip files, 1F 8B = \037\213 */ |
| 930 | if ((fgetc(l_in_file) != 0x1F) || (fgetc(l_in_file) != 0x8b)) { | 946 | if (( magic [0] != 0x1F ) || ( magic [1] != 0x8b)) { |
| 931 | error_msg("Invalid gzip magic"); | 947 | error_msg("Invalid gzip magic"); |
| 932 | return EXIT_FAILURE; | 948 | return EXIT_FAILURE; |
| 933 | } | 949 | } |
diff --git a/sysdeps/linux/config.in b/sysdeps/linux/config.in index c1461602a..f1b064a40 100644 --- a/sysdeps/linux/config.in +++ b/sysdeps/linux/config.in | |||
| @@ -14,6 +14,7 @@ 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 | ||
| 17 | bool 'Clean up all memory before exiting (usually not needed)' CONFIG_FEATURE_CLEAN_UP | 18 | bool 'Clean up all memory before exiting (usually not needed)' CONFIG_FEATURE_CLEAN_UP |
| 18 | endmenu | 19 | endmenu |
| 19 | 20 | ||
