gzip.c (337521) | gzip.c (343251) |
---|---|
1/* $NetBSD: gzip.c,v 1.113 2018/06/12 00:42:17 kamil Exp $ */ | 1/* $NetBSD: gzip.c,v 1.116 2018/10/27 11:39:12 skrll Exp $ */ |
2 3/*- 4 * SPDX-License-Identifier: BSD-2-Clause-NetBSD 5 * 6 * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017 7 * Matthew R. Green 8 * All rights reserved. 9 * --- 19 unchanged lines hidden (view full) --- 29 * SUCH DAMAGE. 30 * 31 */ 32 33#include <sys/cdefs.h> 34#ifndef lint 35__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\ 36 2009, 2010, 2011, 2015, 2017 Matthew R. Green. All rights reserved."); | 2 3/*- 4 * SPDX-License-Identifier: BSD-2-Clause-NetBSD 5 * 6 * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017 7 * Matthew R. Green 8 * All rights reserved. 9 * --- 19 unchanged lines hidden (view full) --- 29 * SUCH DAMAGE. 30 * 31 */ 32 33#include <sys/cdefs.h> 34#ifndef lint 35__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\ 36 2009, 2010, 2011, 2015, 2017 Matthew R. Green. All rights reserved."); |
37__FBSDID("$FreeBSD: stable/11/usr.bin/gzip/gzip.c 337521 2018-08-09 02:27:18Z delphij $"); | 37__FBSDID("$FreeBSD: stable/11/usr.bin/gzip/gzip.c 343251 2019-01-21 06:52:35Z delphij $"); |
38#endif /* not lint */ 39 40/* 41 * gzip.c -- GPL free gzip using zlib. 42 * 43 * RFC 1950 covers the zlib format 44 * RFC 1951 covers the deflate format 45 * RFC 1952 covers the gzip format --- 33 unchanged lines hidden (view full) --- 79 FT_Z, 80#endif 81#ifndef NO_PACK_SUPPORT 82 FT_PACK, 83#endif 84#ifndef NO_XZ_SUPPORT 85 FT_XZ, 86#endif | 38#endif /* not lint */ 39 40/* 41 * gzip.c -- GPL free gzip using zlib. 42 * 43 * RFC 1950 covers the zlib format 44 * RFC 1951 covers the deflate format 45 * RFC 1952 covers the gzip format --- 33 unchanged lines hidden (view full) --- 79 FT_Z, 80#endif 81#ifndef NO_PACK_SUPPORT 82 FT_PACK, 83#endif 84#ifndef NO_XZ_SUPPORT 85 FT_XZ, 86#endif |
87#ifndef NO_LZ_SUPPORT 88 FT_LZ, 89#endif |
|
87 FT_LAST, 88 FT_UNKNOWN 89}; 90 91#ifndef NO_BZIP2_SUPPORT 92#include <bzlib.h> 93 94#define BZ2_SUFFIX ".bz2" --- 10 unchanged lines hidden (view full) --- 105#endif 106 107#ifndef NO_XZ_SUPPORT 108#include <lzma.h> 109#define XZ_SUFFIX ".xz" 110#define XZ_MAGIC "\3757zXZ" 111#endif 112 | 90 FT_LAST, 91 FT_UNKNOWN 92}; 93 94#ifndef NO_BZIP2_SUPPORT 95#include <bzlib.h> 96 97#define BZ2_SUFFIX ".bz2" --- 10 unchanged lines hidden (view full) --- 108#endif 109 110#ifndef NO_XZ_SUPPORT 111#include <lzma.h> 112#define XZ_SUFFIX ".xz" 113#define XZ_MAGIC "\3757zXZ" 114#endif 115 |
116#ifndef NO_LZ_SUPPORT 117#define LZ_SUFFIX ".lz" 118#define LZ_MAGIC "LZIP" 119#endif 120 |
|
113#define GZ_SUFFIX ".gz" 114 115#define BUFLEN (64 * 1024) 116 117#define GZIP_MAGIC0 0x1F 118#define GZIP_MAGIC1 0x8B 119#define GZIP_OMAGIC1 0x9E 120 --- 29 unchanged lines hidden (view full) --- 150 SUFFIX(".tbz2", ".tar"), 151#endif 152#ifndef NO_COMPRESS_SUPPORT 153 SUFFIX(Z_SUFFIX, ""), 154#endif 155#ifndef NO_XZ_SUPPORT 156 SUFFIX(XZ_SUFFIX, ""), 157#endif | 121#define GZ_SUFFIX ".gz" 122 123#define BUFLEN (64 * 1024) 124 125#define GZIP_MAGIC0 0x1F 126#define GZIP_MAGIC1 0x8B 127#define GZIP_OMAGIC1 0x9E 128 --- 29 unchanged lines hidden (view full) --- 158 SUFFIX(".tbz2", ".tar"), 159#endif 160#ifndef NO_COMPRESS_SUPPORT 161 SUFFIX(Z_SUFFIX, ""), 162#endif 163#ifndef NO_XZ_SUPPORT 164 SUFFIX(XZ_SUFFIX, ""), 165#endif |
166#ifndef NO_LZ_SUPPORT 167 SUFFIX(LZ_SUFFIX, ""), 168#endif |
|
158 SUFFIX(GZ_SUFFIX, ""), /* Overwritten by -S "" */ 159#endif /* SMALL */ 160#undef SUFFIX 161}; 162#define NUM_SUFFIXES (nitems(suffixes)) 163#define SUFFIX_MAXLEN 30 164 | 169 SUFFIX(GZ_SUFFIX, ""), /* Overwritten by -S "" */ 170#endif /* SMALL */ 171#undef SUFFIX 172}; 173#define NUM_SUFFIXES (nitems(suffixes)) 174#define SUFFIX_MAXLEN 30 175 |
165static const char gzip_version[] = "FreeBSD gzip 20171121"; | 176static const char gzip_version[] = "FreeBSD gzip 20190107"; |
166 167#ifndef SMALL 168static const char gzip_copyright[] = \ 169" Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green\n" 170" All rights reserved.\n" 171"\n" 172" Redistribution and use in source and binary forms, with or without\n" 173" modification, are permitted provided that the following conditions\n" --- 67 unchanged lines hidden (view full) --- 241static void usage(void) __dead2; 242static void display_version(void) __dead2; 243#ifndef SMALL 244static void display_license(void); 245#endif 246static const suffixes_t *check_suffix(char *, int); 247static ssize_t read_retry(int, void *, size_t); 248static ssize_t write_retry(int, const void *, size_t); | 177 178#ifndef SMALL 179static const char gzip_copyright[] = \ 180" Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green\n" 181" All rights reserved.\n" 182"\n" 183" Redistribution and use in source and binary forms, with or without\n" 184" modification, are permitted provided that the following conditions\n" --- 67 unchanged lines hidden (view full) --- 252static void usage(void) __dead2; 253static void display_version(void) __dead2; 254#ifndef SMALL 255static void display_license(void); 256#endif 257static const suffixes_t *check_suffix(char *, int); 258static ssize_t read_retry(int, void *, size_t); 259static ssize_t write_retry(int, const void *, size_t); |
260static void print_list_out(off_t, off_t, const char*); |
|
249 250#ifdef SMALL 251#define infile_set(f,t) infile_set(f) 252#endif 253static void infile_set(const char *newinfile, off_t total); 254 255#ifdef SMALL 256#define unlink_input(f, sb) unlink(f) --- 27 unchanged lines hidden (view full) --- 284#endif 285 286#ifndef NO_PACK_SUPPORT 287static off_t unpack(int, int, char *, size_t, off_t *); 288#endif 289 290#ifndef NO_XZ_SUPPORT 291static off_t unxz(int, int, char *, size_t, off_t *); | 261 262#ifdef SMALL 263#define infile_set(f,t) infile_set(f) 264#endif 265static void infile_set(const char *newinfile, off_t total); 266 267#ifdef SMALL 268#define unlink_input(f, sb) unlink(f) --- 27 unchanged lines hidden (view full) --- 296#endif 297 298#ifndef NO_PACK_SUPPORT 299static off_t unpack(int, int, char *, size_t, off_t *); 300#endif 301 302#ifndef NO_XZ_SUPPORT 303static off_t unxz(int, int, char *, size_t, off_t *); |
304static off_t unxz_len(int); |
|
292#endif 293 | 305#endif 306 |
307#ifndef NO_LZ_SUPPORT 308static off_t unlz(int, int, char *, size_t, off_t *); 309#endif 310 |
|
294#ifdef SMALL 295#define getopt_long(a,b,c,d,e) getopt(a,b,c) 296#else 297static const struct option longopts[] = { 298 { "stdout", no_argument, 0, 'c' }, 299 { "to-stdout", no_argument, 0, 'c' }, 300 { "decompress", no_argument, 0, 'd' }, 301 { "uncompress", no_argument, 0, 'd' }, --- 852 unchanged lines hidden (view full) --- 1154 return FT_PACK; 1155 else 1156#endif 1157#ifndef NO_XZ_SUPPORT 1158 if (memcmp(buf, XZ_MAGIC, 4) == 0) /* XXX: We only have 4 bytes */ 1159 return FT_XZ; 1160 else 1161#endif | 311#ifdef SMALL 312#define getopt_long(a,b,c,d,e) getopt(a,b,c) 313#else 314static const struct option longopts[] = { 315 { "stdout", no_argument, 0, 'c' }, 316 { "to-stdout", no_argument, 0, 'c' }, 317 { "decompress", no_argument, 0, 'd' }, 318 { "uncompress", no_argument, 0, 'd' }, --- 852 unchanged lines hidden (view full) --- 1171 return FT_PACK; 1172 else 1173#endif 1174#ifndef NO_XZ_SUPPORT 1175 if (memcmp(buf, XZ_MAGIC, 4) == 0) /* XXX: We only have 4 bytes */ 1176 return FT_XZ; 1177 else 1178#endif |
1179#ifndef NO_LZ_SUPPORT 1180 if (memcmp(buf, LZ_MAGIC, 4) == 0) 1181 return FT_LZ; 1182 else 1183#endif |
|
1162 return FT_UNKNOWN; 1163} 1164 1165#ifndef SMALL 1166/* check the outfile is OK. */ 1167static int 1168check_outfile(const char *outfile) 1169{ --- 458 unchanged lines hidden (view full) --- 1628 1629 size = unpack(fd, zfd, NULL, 0, NULL); 1630 break; 1631#endif 1632 1633#ifndef NO_XZ_SUPPORT 1634 case FT_XZ: 1635 if (lflag) { | 1184 return FT_UNKNOWN; 1185} 1186 1187#ifndef SMALL 1188/* check the outfile is OK. */ 1189static int 1190check_outfile(const char *outfile) 1191{ --- 458 unchanged lines hidden (view full) --- 1650 1651 size = unpack(fd, zfd, NULL, 0, NULL); 1652 break; 1653#endif 1654 1655#ifndef NO_XZ_SUPPORT 1656 case FT_XZ: 1657 if (lflag) { |
1636 maybe_warnx("no -l with xz files"); 1637 goto lose; | 1658 size = unxz_len(fd); 1659 print_list_out(in_size, size, file); 1660 return -1; |
1638 } | 1661 } |
1639 | |
1640 size = unxz(fd, zfd, NULL, 0, NULL); 1641 break; 1642#endif 1643 | 1662 size = unxz(fd, zfd, NULL, 0, NULL); 1663 break; 1664#endif 1665 |
1666#ifndef NO_LZ_SUPPORT 1667 case FT_LZ: 1668 if (lflag) { 1669 maybe_warnx("no -l with lzip files"); 1670 goto lose; 1671 } 1672 size = unlz(fd, zfd, NULL, 0, NULL); 1673 break; 1674#endif |
|
1644#ifndef SMALL 1645 case FT_UNKNOWN: 1646 if (lflag) { 1647 maybe_warnx("no -l for unknown filetypes"); 1648 goto lose; 1649 } 1650 size = cat_fd(NULL, 0, NULL, fd); 1651 break; --- 216 unchanged lines hidden (view full) --- 1868 break; 1869#endif 1870#ifndef NO_XZ_SUPPORT 1871 case FT_XZ: 1872 usize = unxz(STDIN_FILENO, STDOUT_FILENO, 1873 (char *)header1, sizeof header1, &gsize); 1874 break; 1875#endif | 1675#ifndef SMALL 1676 case FT_UNKNOWN: 1677 if (lflag) { 1678 maybe_warnx("no -l for unknown filetypes"); 1679 goto lose; 1680 } 1681 size = cat_fd(NULL, 0, NULL, fd); 1682 break; --- 216 unchanged lines hidden (view full) --- 1899 break; 1900#endif 1901#ifndef NO_XZ_SUPPORT 1902 case FT_XZ: 1903 usize = unxz(STDIN_FILENO, STDOUT_FILENO, 1904 (char *)header1, sizeof header1, &gsize); 1905 break; 1906#endif |
1907#ifndef NO_LZ_SUPPORT 1908 case FT_LZ: 1909 usize = unlz(STDIN_FILENO, STDOUT_FILENO, 1910 (char *)header1, sizeof header1, &gsize); 1911 break; 1912#endif |
|
1876 } 1877 1878#ifndef SMALL 1879 if (vflag && !tflag && usize != -1 && gsize != -1) 1880 print_verbage(NULL, NULL, usize, gsize); 1881 if (vflag && tflag) 1882 print_test("(stdin)", usize != -1); 1883#else --- 309 unchanged lines hidden (view full) --- 2193 date[12] = 0; 2194 printf("%5s %08x %11s ", "defla"/*XXX*/, crc, date); 2195 } 2196 in_tot += in; 2197 out_tot += out; 2198#else 2199 (void)&ts; /* XXX */ 2200#endif | 1913 } 1914 1915#ifndef SMALL 1916 if (vflag && !tflag && usize != -1 && gsize != -1) 1917 print_verbage(NULL, NULL, usize, gsize); 1918 if (vflag && tflag) 1919 print_test("(stdin)", usize != -1); 1920#else --- 309 unchanged lines hidden (view full) --- 2230 date[12] = 0; 2231 printf("%5s %08x %11s ", "defla"/*XXX*/, crc, date); 2232 } 2233 in_tot += in; 2234 out_tot += out; 2235#else 2236 (void)&ts; /* XXX */ 2237#endif |
2238 print_list_out(out, in, outfile); 2239} 2240 2241static void 2242print_list_out(off_t out, off_t in, const char *outfile) 2243{ |
|
2201 printf("%12llu %12llu ", (unsigned long long)out, (unsigned long long)in); 2202 print_ratio(in, out, stdout); 2203 printf(" %s\n", outfile); 2204} 2205 2206/* display the usage of NetBSD gzip */ 2207static void 2208usage(void) --- 58 unchanged lines hidden (view full) --- 2267#include "zuncompress.c" 2268#endif 2269#ifndef NO_PACK_SUPPORT 2270#include "unpack.c" 2271#endif 2272#ifndef NO_XZ_SUPPORT 2273#include "unxz.c" 2274#endif | 2244 printf("%12llu %12llu ", (unsigned long long)out, (unsigned long long)in); 2245 print_ratio(in, out, stdout); 2246 printf(" %s\n", outfile); 2247} 2248 2249/* display the usage of NetBSD gzip */ 2250static void 2251usage(void) --- 58 unchanged lines hidden (view full) --- 2310#include "zuncompress.c" 2311#endif 2312#ifndef NO_PACK_SUPPORT 2313#include "unpack.c" 2314#endif 2315#ifndef NO_XZ_SUPPORT 2316#include "unxz.c" 2317#endif |
2318#ifndef NO_LZ_SUPPORT 2319#include "unlz.c" 2320#endif |
|
2275 2276static ssize_t 2277read_retry(int fd, void *buf, size_t sz) 2278{ 2279 char *cp = buf; 2280 size_t left = MIN(sz, (size_t) SSIZE_MAX); 2281 2282 while (left > 0) { --- 36 unchanged lines hidden --- | 2321 2322static ssize_t 2323read_retry(int fd, void *buf, size_t sz) 2324{ 2325 char *cp = buf; 2326 size_t left = MIN(sz, (size_t) SSIZE_MAX); 2327 2328 while (left > 0) { --- 36 unchanged lines hidden --- |