diff options
author | delphij <delphij@FreeBSD.org> | 2009-06-21 09:39:43 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2009-06-21 09:39:43 +0000 |
commit | bfca5b766dcbba5d363d14ad19521182daf04b69 (patch) | |
tree | 20cdabcc5121b0edf6288ffb974d348e38352119 /usr.bin/gzip/gzip.c | |
parent | b541bd5a39b43c11067cf9193020c5fa63df0e65 (diff) | |
download | FreeBSD-src-bfca5b766dcbba5d363d14ad19521182daf04b69.zip FreeBSD-src-bfca5b766dcbba5d363d14ad19521182daf04b69.tar.gz |
Add support for uncompressing pack(1)'ed files. Pack(1) is a program found
in some commercial Unix systems, which utilizes Huffman minimum redundancy
code tree to compress files. This implementation supports the "new" pack
format only, just like GNU gzip did.
Thanks for oliver@'s archive set which I can test against, and Mingyan Guo
for providing helpful review of my code.
PR: bin/109567
MFC after: 1 month
Diffstat (limited to 'usr.bin/gzip/gzip.c')
-rw-r--r-- | usr.bin/gzip/gzip.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/usr.bin/gzip/gzip.c b/usr.bin/gzip/gzip.c index e33acc8..bdff534 100644 --- a/usr.bin/gzip/gzip.c +++ b/usr.bin/gzip/gzip.c @@ -79,6 +79,9 @@ enum filetype { #ifndef NO_COMPRESS_SUPPORT FT_Z, #endif +#ifndef NO_PACK_SUPPORT + FT_PACK, +#endif FT_LAST, FT_UNKNOWN }; @@ -95,6 +98,10 @@ enum filetype { #define Z_MAGIC "\037\235" #endif +#ifndef NO_PACK_SUPPORT +#define PACK_MAGIC "\037\036" +#endif + #define GZ_SUFFIX ".gz" #define BUFLEN (64 * 1024) @@ -143,7 +150,7 @@ static suffixes_t suffixes[] = { }; #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0]) -static const char gzip_version[] = "FreeBSD gzip 20070711"; +static const char gzip_version[] = "FreeBSD gzip 20090621"; #ifndef SMALL static const char gzip_copyright[] = \ @@ -248,6 +255,10 @@ static FILE *zdopen(int); static off_t zuncompress(FILE *, FILE *, char *, size_t, off_t *); #endif +#ifndef NO_PACK_SUPPORT +static off_t unpack(int, int, char *, size_t, off_t *); +#endif + int main(int, char **p); #ifdef SMALL @@ -1104,6 +1115,11 @@ file_gettype(u_char *buf) return FT_Z; else #endif +#ifndef NO_PACK_SUPPORT + if (memcmp(buf, PACK_MAGIC, 2) == 0) + return FT_PACK; + else +#endif return FT_UNKNOWN; } @@ -1458,6 +1474,17 @@ file_uncompress(char *file, char *outfile, size_t outsize) } else #endif +#ifndef NO_PACK_SUPPORT + if (method == FT_PACK) { + if (lflag) { + maybe_warnx("no -l with packed files"); + goto lose; + } + + size = unpack(fd, zfd, NULL, 0, NULL); + } else +#endif + #ifndef SMALL if (method == FT_UNKNOWN) { if (lflag) { @@ -1651,6 +1678,12 @@ handle_stdin(void) fclose(in); break; #endif +#ifndef NO_PACK_SUPPORT + case FT_PACK: + usize = unpack(STDIN_FILENO, STDOUT_FILENO, + (char *)header1, sizeof header1, &gsize); + break; +#endif } #ifndef SMALL @@ -2038,6 +2071,9 @@ display_version(void) #ifndef NO_COMPRESS_SUPPORT #include "zuncompress.c" #endif +#ifndef NO_PACK_SUPPORT +#include "unpack.c" +#endif static ssize_t read_retry(int fd, void *buf, size_t sz) |