Remove SMALL conditionals from gzip

gzip has SMALL conditionals which enable building a reduced size version
of the binary. These exist as part of the introduction of BSD licensed
gzip in 2004 in NetBSD and appear to have been required to reach a size
for inclusion in their install media. For more information see commits
to gzip in the NetBSD tree on the 28th of March 2004.

SMALL doesn't appear to be hooked up to our build system and
complicates gzip quite a bit.

Reviewed by:	kevans,	imp
Sponsored by:	Klara Inc.
Differential Revision:	https://reviews.freebsd.org/D34047
This commit is contained in:
Tom Jones 2022-01-27 17:24:45 +00:00
parent c9afc7680f
commit 4669f23ef7

View File

@ -144,7 +144,6 @@ typedef struct {
static suffixes_t suffixes[] = { static suffixes_t suffixes[] = {
#define SUFFIX(Z, N) {Z, sizeof Z - 1, N} #define SUFFIX(Z, N) {Z, sizeof Z - 1, N}
SUFFIX(GZ_SUFFIX, ""), /* Overwritten by -S .xxx */ SUFFIX(GZ_SUFFIX, ""), /* Overwritten by -S .xxx */
#ifndef SMALL
SUFFIX(GZ_SUFFIX, ""), SUFFIX(GZ_SUFFIX, ""),
SUFFIX(".z", ""), SUFFIX(".z", ""),
SUFFIX("-gz", ""), SUFFIX("-gz", ""),
@ -167,7 +166,6 @@ static suffixes_t suffixes[] = {
SUFFIX(LZ_SUFFIX, ""), SUFFIX(LZ_SUFFIX, ""),
#endif #endif
SUFFIX(GZ_SUFFIX, ""), /* Overwritten by -S "" */ SUFFIX(GZ_SUFFIX, ""), /* Overwritten by -S "" */
#endif /* SMALL */
#undef SUFFIX #undef SUFFIX
}; };
#define NUM_SUFFIXES (nitems(suffixes)) #define NUM_SUFFIXES (nitems(suffixes))
@ -175,7 +173,6 @@ static suffixes_t suffixes[] = {
static const char gzip_version[] = "FreeBSD gzip 20190107"; static const char gzip_version[] = "FreeBSD gzip 20190107";
#ifndef SMALL
static const char gzip_copyright[] = \ static const char gzip_copyright[] = \
" Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green\n" " Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green\n"
" All rights reserved.\n" " All rights reserved.\n"
@ -200,7 +197,6 @@ static const char gzip_copyright[] = \
" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n" " OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\n"
" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n" " OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"
" SUCH DAMAGE."; " SUCH DAMAGE.";
#endif
static int cflag; /* stdout mode */ static int cflag; /* stdout mode */
static int dflag; /* decompress mode */ static int dflag; /* decompress mode */
@ -210,7 +206,6 @@ static int numflag = 6; /* gzip -1..-9 value */
static const char *remove_file = NULL; /* file to be removed upon SIGINT */ static const char *remove_file = NULL; /* file to be removed upon SIGINT */
static int fflag; /* force mode */ static int fflag; /* force mode */
#ifndef SMALL
static int kflag; /* don't delete input files */ static int kflag; /* don't delete input files */
static int nflag; /* don't save name/timestamp */ static int nflag; /* don't save name/timestamp */
static int Nflag; /* don't restore name/timestamp */ static int Nflag; /* don't restore name/timestamp */
@ -219,10 +214,6 @@ static int rflag; /* recursive mode */
static int tflag; /* test */ static int tflag; /* test */
static int vflag; /* verbose mode */ static int vflag; /* verbose mode */
static sig_atomic_t print_info = 0; static sig_atomic_t print_info = 0;
#else
#define qflag 0
#define tflag 0
#endif
static int exit_value = 0; /* exit value */ static int exit_value = 0; /* exit value */
@ -236,9 +227,6 @@ static void maybe_errx(const char *fmt, ...) __printflike(1, 2) __dead2;
static void maybe_warn(const char *fmt, ...) __printflike(1, 2); static void maybe_warn(const char *fmt, ...) __printflike(1, 2);
static void maybe_warnx(const char *fmt, ...) __printflike(1, 2); static void maybe_warnx(const char *fmt, ...) __printflike(1, 2);
static enum filetype file_gettype(u_char *); static enum filetype file_gettype(u_char *);
#ifdef SMALL
#define gz_compress(if, of, sz, fn, tm) gz_compress(if, of, sz)
#endif
static off_t gz_compress(int, int, off_t *, const char *, uint32_t); static off_t gz_compress(int, int, off_t *, const char *, uint32_t);
static off_t gz_uncompress(int, int, char *, size_t, off_t *, const char *); static off_t gz_uncompress(int, int, char *, size_t, off_t *, const char *);
static off_t file_compress(char *, char *, size_t); static off_t file_compress(char *, char *, size_t);
@ -251,25 +239,14 @@ static void print_ratio(off_t, off_t, FILE *);
static void print_list(int fd, off_t, const char *, time_t); static void print_list(int fd, off_t, const char *, time_t);
static void usage(void) __dead2; static void usage(void) __dead2;
static void display_version(void) __dead2; static void display_version(void) __dead2;
#ifndef SMALL
static void display_license(void); static void display_license(void);
#endif
static const suffixes_t *check_suffix(char *, int); static const suffixes_t *check_suffix(char *, int);
static ssize_t read_retry(int, void *, size_t); static ssize_t read_retry(int, void *, size_t);
static ssize_t write_retry(int, const void *, size_t); static ssize_t write_retry(int, const void *, size_t);
static void print_list_out(off_t, off_t, const char*); static void print_list_out(off_t, off_t, const char*);
#ifdef SMALL
#define infile_set(f,t) infile_set(f)
#endif
static void infile_set(const char *newinfile, off_t total); static void infile_set(const char *newinfile, off_t total);
#ifdef SMALL
#define unlink_input(f, sb) unlink(f)
#define check_siginfo() /* nothing */
#define setup_signals() /* nothing */
#define infile_newdata(t) /* nothing */
#else
static off_t infile_total; /* total expected to read/write */ static off_t infile_total; /* total expected to read/write */
static off_t infile_current; /* current read/write */ static off_t infile_current; /* current read/write */
@ -284,7 +261,6 @@ static int check_outfile(const char *outfile);
static void setup_signals(void); static void setup_signals(void);
static void infile_newdata(size_t newdata); static void infile_newdata(size_t newdata);
static void infile_clear(void); static void infile_clear(void);
#endif
#ifndef NO_BZIP2_SUPPORT #ifndef NO_BZIP2_SUPPORT
static off_t unbzip2(int, int, char *, size_t, off_t *); static off_t unbzip2(int, int, char *, size_t, off_t *);
@ -308,9 +284,6 @@ static off_t unxz_len(int);
static off_t unlz(int, int, char *, size_t, off_t *); static off_t unlz(int, int, char *, size_t, off_t *);
#endif #endif
#ifdef SMALL
#define getopt_long(a,b,c,d,e) getopt(a,b,c)
#else
static const struct option longopts[] = { static const struct option longopts[] = {
{ "stdout", no_argument, 0, 'c' }, { "stdout", no_argument, 0, 'c' },
{ "to-stdout", no_argument, 0, 'c' }, { "to-stdout", no_argument, 0, 'c' },
@ -334,24 +307,19 @@ static const struct option longopts[] = {
{ "license", no_argument, 0, 'L' }, { "license", no_argument, 0, 'L' },
{ NULL, no_argument, 0, 0 }, { NULL, no_argument, 0, 0 },
}; };
#endif
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
const char *progname = getprogname(); const char *progname = getprogname();
#ifndef SMALL
char *gzip; char *gzip;
int len; int len;
#endif
int ch; int ch;
setup_signals(); setup_signals();
#ifndef SMALL
if ((gzip = getenv("GZIP")) != NULL) if ((gzip = getenv("GZIP")) != NULL)
prepend_gzip(gzip, &argc, &argv); prepend_gzip(gzip, &argc, &argv);
#endif
/* /*
* XXX * XXX
@ -363,11 +331,7 @@ main(int argc, char **argv)
strcmp(progname, "gzcat") == 0) strcmp(progname, "gzcat") == 0)
dflag = cflag = 1; dflag = cflag = 1;
#ifdef SMALL
#define OPT_LIST "123456789cdhlV"
#else
#define OPT_LIST "123456789acdfhklLNnqrS:tVv" #define OPT_LIST "123456789acdfhklLNnqrS:tVv"
#endif
while ((ch = getopt_long(argc, argv, OPT_LIST, longopts, NULL)) != -1) { while ((ch = getopt_long(argc, argv, OPT_LIST, longopts, NULL)) != -1) {
switch (ch) { switch (ch) {
@ -389,7 +353,6 @@ main(int argc, char **argv)
case 'V': case 'V':
display_version(); display_version();
/* NOTREACHED */ /* NOTREACHED */
#ifndef SMALL
case 'a': case 'a':
fprintf(stderr, "%s: option --ascii ignored on this system\n", progname); fprintf(stderr, "%s: option --ascii ignored on this system\n", progname);
break; break;
@ -436,7 +399,6 @@ main(int argc, char **argv)
case 'v': case 'v':
vflag = 1; vflag = 1;
break; break;
#endif
default: default:
usage(); usage();
/* NOTREACHED */ /* NOTREACHED */
@ -455,10 +417,8 @@ main(int argc, char **argv)
handle_pathname(argv[0]); handle_pathname(argv[0]);
} while (*++argv); } while (*++argv);
} }
#ifndef SMALL
if (qflag == 0 && lflag && argc > 1) if (qflag == 0 && lflag && argc > 1)
print_list(-1, 0, "(totals)", 0); print_list(-1, 0, "(totals)", 0);
#endif
exit(exit_value); exit(exit_value);
} }
@ -523,7 +483,6 @@ maybe_errx(const char *fmt, ...)
} }
#endif #endif
#ifndef SMALL
/* split up $GZIP and prepend it to the argument list */ /* split up $GZIP and prepend it to the argument list */
static void static void
prepend_gzip(char *gzip, int *argc, char ***argv) prepend_gzip(char *gzip, int *argc, char ***argv)
@ -587,7 +546,6 @@ prepend_gzip(char *gzip, int *argc, char ***argv)
nargv[i++] = *(ac++); nargv[i++] = *(ac++);
nargv[i] = NULL; nargv[i] = NULL;
} }
#endif
/* compress input to output. Return bytes read, -1 on error */ /* compress input to output. Return bytes read, -1 on error */
static off_t static off_t
@ -599,11 +557,6 @@ gz_compress(int in, int out, off_t *gsizep, const char *origname, uint32_t mtime
ssize_t in_size; ssize_t in_size;
int i, error; int i, error;
uLong crc; uLong crc;
#ifdef SMALL
static char header[] = { GZIP_MAGIC0, GZIP_MAGIC1, Z_DEFLATED, 0,
0, 0, 0, 0,
0, OS_CODE };
#endif
outbufp = malloc(BUFLEN); outbufp = malloc(BUFLEN);
inbufp = malloc(BUFLEN); inbufp = malloc(BUFLEN);
@ -617,10 +570,6 @@ gz_compress(int in, int out, off_t *gsizep, const char *origname, uint32_t mtime
z.zfree = Z_NULL; z.zfree = Z_NULL;
z.opaque = 0; z.opaque = 0;
#ifdef SMALL
memcpy(outbufp, header, sizeof header);
i = sizeof header;
#else
if (nflag != 0) { if (nflag != 0) {
mtime = 0; mtime = 0;
origname = ""; origname = "";
@ -640,7 +589,6 @@ gz_compress(int in, int out, off_t *gsizep, const char *origname, uint32_t mtime
maybe_err("snprintf"); maybe_err("snprintf");
if (*origname) if (*origname)
i++; i++;
#endif
z.next_out = (unsigned char *)outbufp + i; z.next_out = (unsigned char *)outbufp + i;
z.avail_out = BUFLEN - i; z.avail_out = BUFLEN - i;
@ -1000,10 +948,8 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
if (wr != 0) { if (wr != 0) {
crc = crc32(crc, (const Bytef *)outbufp, (unsigned)wr); crc = crc32(crc, (const Bytef *)outbufp, (unsigned)wr);
if ( if (
#ifndef SMALL
/* don't write anything with -t */ /* don't write anything with -t */
tflag == 0 && tflag == 0 &&
#endif
write_retry(out, outbufp, wr) != wr) { write_retry(out, outbufp, wr) != wr) {
maybe_warn("error writing to output"); maybe_warn("error writing to output");
goto stop_and_fail; goto stop_and_fail;
@ -1099,7 +1045,6 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
return (out_tot); return (out_tot);
} }
#ifndef SMALL
/* /*
* set the owner, mode, flags & utimes using the given file descriptor. * set the owner, mode, flags & utimes using the given file descriptor.
* file is only used in possible warning messages. * file is only used in possible warning messages.
@ -1144,7 +1089,6 @@ copymodes(int fd, const struct stat *sbp, const char *file)
if (sb.st_flags != 0 && fchflags(fd, sb.st_flags) < 0) if (sb.st_flags != 0 && fchflags(fd, sb.st_flags) < 0)
maybe_warn("couldn't fchflags: %s", file); maybe_warn("couldn't fchflags: %s", file);
} }
#endif
/* what sort of file is this? */ /* what sort of file is this? */
static enum filetype static enum filetype
@ -1184,7 +1128,6 @@ file_gettype(u_char *buf)
return FT_UNKNOWN; return FT_UNKNOWN;
} }
#ifndef SMALL
/* check the outfile is OK. */ /* check the outfile is OK. */
static int static int
check_outfile(const char *outfile) check_outfile(const char *outfile)
@ -1260,7 +1203,6 @@ infile_newdata(size_t newdata)
infile_current += newdata; infile_current += newdata;
} }
#endif
static void static void
infile_set(const char *newinfile, off_t total) infile_set(const char *newinfile, off_t total)
@ -1268,9 +1210,7 @@ infile_set(const char *newinfile, off_t total)
if (newinfile) if (newinfile)
infile = newinfile; infile = newinfile;
#ifndef SMALL
infile_total = total; infile_total = total;
#endif
} }
static void static void
@ -1278,9 +1218,7 @@ infile_clear(void)
{ {
infile = NULL; infile = NULL;
#ifndef SMALL
infile_total = infile_current = 0; infile_total = infile_current = 0;
#endif
} }
static const suffixes_t * static const suffixes_t *
@ -1314,10 +1252,8 @@ file_compress(char *file, char *outfile, size_t outsize)
int in; int in;
int out; int out;
off_t size, in_size; off_t size, in_size;
#ifndef SMALL
struct stat isb, osb; struct stat isb, osb;
const suffixes_t *suff; const suffixes_t *suff;
#endif
in = open(file, O_RDONLY); in = open(file, O_RDONLY);
if (in == -1) { if (in == -1) {
@ -1325,25 +1261,20 @@ file_compress(char *file, char *outfile, size_t outsize)
return (-1); return (-1);
} }
#ifndef SMALL
if (fstat(in, &isb) != 0) { if (fstat(in, &isb) != 0) {
maybe_warn("couldn't stat: %s", file); maybe_warn("couldn't stat: %s", file);
close(in); close(in);
return (-1); return (-1);
} }
#endif
#ifndef SMALL
if (fstat(in, &isb) != 0) { if (fstat(in, &isb) != 0) {
close(in); close(in);
maybe_warn("can't stat %s", file); maybe_warn("can't stat %s", file);
return -1; return -1;
} }
infile_set(file, isb.st_size); infile_set(file, isb.st_size);
#endif
if (cflag == 0) { if (cflag == 0) {
#ifndef SMALL
if (isb.st_nlink > 1 && fflag == 0) { if (isb.st_nlink > 1 && fflag == 0) {
maybe_warnx("%s has %ju other link%s -- " maybe_warnx("%s has %ju other link%s -- "
"skipping", file, "skipping", file,
@ -1360,7 +1291,6 @@ file_compress(char *file, char *outfile, size_t outsize)
close(in); close(in);
return (-1); return (-1);
} }
#endif
/* Add (usually) .gz to filename */ /* Add (usually) .gz to filename */
if ((size_t)snprintf(outfile, outsize, "%s%s", if ((size_t)snprintf(outfile, outsize, "%s%s",
@ -1368,12 +1298,10 @@ file_compress(char *file, char *outfile, size_t outsize)
memcpy(outfile + outsize - suffixes[0].ziplen - 1, memcpy(outfile + outsize - suffixes[0].ziplen - 1,
suffixes[0].zipped, suffixes[0].ziplen + 1); suffixes[0].zipped, suffixes[0].ziplen + 1);
#ifndef SMALL
if (check_outfile(outfile) == 0) { if (check_outfile(outfile) == 0) {
close(in); close(in);
return (-1); return (-1);
} }
#endif
} }
if (cflag == 0) { if (cflag == 0) {
@ -1383,9 +1311,7 @@ file_compress(char *file, char *outfile, size_t outsize)
fclose(stdin); fclose(stdin);
return (-1); return (-1);
} }
#ifndef SMALL
remove_file = outfile; remove_file = outfile;
#endif
} else } else
out = STDOUT_FILENO; out = STDOUT_FILENO;
@ -1403,7 +1329,6 @@ file_compress(char *file, char *outfile, size_t outsize)
if (cflag != 0) if (cflag != 0)
return in_size == -1 ? -1 : size; return in_size == -1 ? -1 : size;
#ifndef SMALL
if (fstat(out, &osb) != 0) { if (fstat(out, &osb) != 0) {
maybe_warn("couldn't stat: %s", outfile); maybe_warn("couldn't stat: %s", outfile);
goto bad_outfile; goto bad_outfile;
@ -1417,7 +1342,6 @@ file_compress(char *file, char *outfile, size_t outsize)
copymodes(out, &isb, outfile); copymodes(out, &isb, outfile);
remove_file = NULL; remove_file = NULL;
#endif
if (close(out) == -1) if (close(out) == -1)
maybe_warn("couldn't close output"); maybe_warn("couldn't close output");
@ -1425,7 +1349,6 @@ file_compress(char *file, char *outfile, size_t outsize)
unlink_input(file, &isb); unlink_input(file, &isb);
return (size); return (size);
#ifndef SMALL
bad_outfile: bad_outfile:
if (close(out) == -1) if (close(out) == -1)
maybe_warn("couldn't close output"); maybe_warn("couldn't close output");
@ -1433,7 +1356,6 @@ file_compress(char *file, char *outfile, size_t outsize)
maybe_warnx("leaving original %s", file); maybe_warnx("leaving original %s", file);
unlink(outfile); unlink(outfile);
return (size); return (size);
#endif
} }
/* uncompress the given file and remove the original */ /* uncompress the given file and remove the original */
@ -1448,11 +1370,9 @@ file_uncompress(char *file, char *outfile, size_t outsize)
int fd, ofd, zfd = -1; int fd, ofd, zfd = -1;
int error; int error;
size_t in_size; size_t in_size;
#ifndef SMALL
ssize_t rv; ssize_t rv;
time_t timestamp = 0; time_t timestamp = 0;
char name[PATH_MAX + 1]; char name[PATH_MAX + 1];
#endif
/* gather the old name info */ /* gather the old name info */
@ -1480,10 +1400,8 @@ file_uncompress(char *file, char *outfile, size_t outsize)
rbytes = read(fd, fourbytes, sizeof fourbytes); rbytes = read(fd, fourbytes, sizeof fourbytes);
if (rbytes != sizeof fourbytes) { if (rbytes != sizeof fourbytes) {
/* we don't want to fail here. */ /* we don't want to fail here. */
#ifndef SMALL
if (fflag) if (fflag)
goto lose; goto lose;
#endif
if (rbytes == -1) if (rbytes == -1)
maybe_warn("can't read %s", file); maybe_warn("can't read %s", file);
else else
@ -1493,15 +1411,12 @@ file_uncompress(char *file, char *outfile, size_t outsize)
infile_newdata(rbytes); infile_newdata(rbytes);
method = file_gettype(fourbytes); method = file_gettype(fourbytes);
#ifndef SMALL
if (fflag == 0 && method == FT_UNKNOWN) { if (fflag == 0 && method == FT_UNKNOWN) {
maybe_warnx("%s: not in gzip format", file); maybe_warnx("%s: not in gzip format", file);
goto lose; goto lose;
} }
#endif
#ifndef SMALL
if (method == FT_GZIP && Nflag) { if (method == FT_GZIP && Nflag) {
unsigned char ts[4]; /* timestamp */ unsigned char ts[4]; /* timestamp */
@ -1547,11 +1462,9 @@ file_uncompress(char *file, char *outfile, size_t outsize)
} }
} }
} }
#endif
lseek(fd, 0, SEEK_SET); lseek(fd, 0, SEEK_SET);
if (cflag == 0 || lflag) { if (cflag == 0 || lflag) {
#ifndef SMALL
if (isb.st_nlink > 1 && lflag == 0 && fflag == 0) { if (isb.st_nlink > 1 && lflag == 0 && fflag == 0) {
maybe_warnx("%s has %ju other links -- skipping", maybe_warnx("%s has %ju other links -- skipping",
file, (uintmax_t)isb.st_nlink - 1); file, (uintmax_t)isb.st_nlink - 1);
@ -1561,7 +1474,6 @@ file_uncompress(char *file, char *outfile, size_t outsize)
isb.st_mtime = timestamp; isb.st_mtime = timestamp;
if (check_outfile(outfile) == 0) if (check_outfile(outfile) == 0)
goto lose; goto lose;
#endif
} }
if (cflag) if (cflag)
@ -1674,7 +1586,6 @@ file_uncompress(char *file, char *outfile, size_t outsize)
size = unlz(fd, zfd, NULL, 0, NULL); size = unlz(fd, zfd, NULL, 0, NULL);
break; break;
#endif #endif
#ifndef SMALL
case FT_UNKNOWN: case FT_UNKNOWN:
if (lflag) { if (lflag) {
maybe_warnx("no -l for unknown filetypes"); maybe_warnx("no -l for unknown filetypes");
@ -1682,7 +1593,6 @@ file_uncompress(char *file, char *outfile, size_t outsize)
} }
size = cat_fd(NULL, 0, NULL, fd); size = cat_fd(NULL, 0, NULL, fd);
break; break;
#endif
default: default:
if (lflag) { if (lflag) {
print_list(fd, in_size, outfile, isb.st_mtime); print_list(fd, in_size, outfile, isb.st_mtime);
@ -1709,10 +1619,8 @@ file_uncompress(char *file, char *outfile, size_t outsize)
} }
/* if testing, or we uncompressed to stdout, this is all we need */ /* if testing, or we uncompressed to stdout, this is all we need */
#ifndef SMALL
if (tflag) if (tflag)
return size; return size;
#endif
/* if we are uncompressing to stdin, don't remove the file. */ /* if we are uncompressing to stdin, don't remove the file. */
if (cflag) if (cflag)
return size; return size;
@ -1743,10 +1651,8 @@ file_uncompress(char *file, char *outfile, size_t outsize)
unlink(outfile); unlink(outfile);
return -1; return -1;
} }
#ifndef SMALL
copymodes(ofd, &isb, outfile); copymodes(ofd, &isb, outfile);
remove_file = NULL; remove_file = NULL;
#endif
close(ofd); close(ofd);
unlink_input(file, &isb); unlink_input(file, &isb);
return size; return size;
@ -1761,7 +1667,6 @@ file_uncompress(char *file, char *outfile, size_t outsize)
return -1; return -1;
} }
#ifndef SMALL
static void static void
check_siginfo(void) check_siginfo(void)
{ {
@ -1817,7 +1722,6 @@ cat_fd(unsigned char * prepend, size_t count, off_t *gsizep, int fd)
*gsizep = in_tot; *gsizep = in_tot;
return (in_tot); return (in_tot);
} }
#endif
static void static void
handle_stdin(void) handle_stdin(void)
@ -1832,12 +1736,10 @@ handle_stdin(void)
FILE *in; FILE *in;
#endif #endif
#ifndef SMALL
if (fflag == 0 && lflag == 0 && isatty(STDIN_FILENO)) { if (fflag == 0 && lflag == 0 && isatty(STDIN_FILENO)) {
maybe_warnx("standard input is a terminal -- ignoring"); maybe_warnx("standard input is a terminal -- ignoring");
goto out; goto out;
} }
#endif
if (fstat(STDIN_FILENO, &isb) < 0) { if (fstat(STDIN_FILENO, &isb) < 0) {
maybe_warn("fstat"); maybe_warn("fstat");
@ -1866,14 +1768,12 @@ handle_stdin(void)
method = file_gettype(fourbytes); method = file_gettype(fourbytes);
switch (method) { switch (method) {
default: default:
#ifndef SMALL
if (fflag == 0) { if (fflag == 0) {
maybe_warnx("unknown compression format"); maybe_warnx("unknown compression format");
goto out; goto out;
} }
usize = cat_fd(fourbytes, sizeof fourbytes, &gsize, STDIN_FILENO); usize = cat_fd(fourbytes, sizeof fourbytes, &gsize, STDIN_FILENO);
break; break;
#endif
case FT_GZIP: case FT_GZIP:
usize = gz_uncompress(STDIN_FILENO, STDOUT_FILENO, usize = gz_uncompress(STDIN_FILENO, STDOUT_FILENO,
(char *)fourbytes, sizeof fourbytes, &gsize, "(stdin)"); (char *)fourbytes, sizeof fourbytes, &gsize, "(stdin)");
@ -1916,14 +1816,10 @@ handle_stdin(void)
#endif #endif
} }
#ifndef SMALL
if (vflag && !tflag && usize != -1 && gsize != -1) if (vflag && !tflag && usize != -1 && gsize != -1)
print_verbage(NULL, NULL, usize, gsize); print_verbage(NULL, NULL, usize, gsize);
if (vflag && tflag) if (vflag && tflag)
print_test("(stdin)", usize != -1); print_test("(stdin)", usize != -1);
#else
(void)&usize;
#endif
out: out:
infile_clear(); infile_clear();
@ -1933,7 +1829,6 @@ static void
handle_stdout(void) handle_stdout(void)
{ {
off_t gsize; off_t gsize;
#ifndef SMALL
off_t usize; off_t usize;
struct stat sb; struct stat sb;
time_t systime; time_t systime;
@ -1967,12 +1862,9 @@ handle_stdout(void)
} }
usize = usize =
#endif
gz_compress(STDIN_FILENO, STDOUT_FILENO, &gsize, "", mtime); gz_compress(STDIN_FILENO, STDOUT_FILENO, &gsize, "", mtime);
#ifndef SMALL
if (vflag && !tflag && usize != -1 && gsize != -1) if (vflag && !tflag && usize != -1 && gsize != -1)
print_verbage(NULL, NULL, usize, gsize); print_verbage(NULL, NULL, usize, gsize);
#endif
} }
/* do what is asked for, for the path name */ /* do what is asked for, for the path name */
@ -2013,11 +1905,9 @@ handle_pathname(char *path)
} }
if (S_ISDIR(sb.st_mode)) { if (S_ISDIR(sb.st_mode)) {
#ifndef SMALL
if (rflag) if (rflag)
handle_dir(path); handle_dir(path);
else else
#endif
maybe_warnx("%s is a directory", path); maybe_warnx("%s is a directory", path);
goto out; goto out;
} }
@ -2042,10 +1932,8 @@ handle_file(char *file, struct stat *sbp)
infile_set(file, sbp->st_size); infile_set(file, sbp->st_size);
if (dflag) { if (dflag) {
usize = file_uncompress(file, outfile, sizeof(outfile)); usize = file_uncompress(file, outfile, sizeof(outfile));
#ifndef SMALL
if (vflag && tflag) if (vflag && tflag)
print_test(file, usize != -1); print_test(file, usize != -1);
#endif
if (usize == -1) if (usize == -1)
return; return;
gsize = sbp->st_size; gsize = sbp->st_size;
@ -2057,13 +1945,10 @@ handle_file(char *file, struct stat *sbp)
} }
infile_clear(); infile_clear();
#ifndef SMALL
if (vflag && !tflag) if (vflag && !tflag)
print_verbage(file, (cflag) ? NULL : outfile, usize, gsize); print_verbage(file, (cflag) ? NULL : outfile, usize, gsize);
#endif
} }
#ifndef SMALL
/* this is used with -r to recursively descend directories */ /* this is used with -r to recursively descend directories */
static void static void
handle_dir(char *dir) handle_dir(char *dir)
@ -2099,7 +1984,6 @@ handle_dir(char *dir)
warn("error with fts_read %s", dir); warn("error with fts_read %s", dir);
(void)fts_close(fts); (void)fts_close(fts);
} }
#endif
/* print a ratio - size reduction as a fraction of uncompressed size */ /* print a ratio - size reduction as a fraction of uncompressed size */
static void static void
@ -2141,7 +2025,6 @@ print_ratio(off_t in, off_t out, FILE *where)
fprintf(where, "%5s%%", buff); fprintf(where, "%5s%%", buff);
} }
#ifndef SMALL
/* print compression statistics, and the new name (if there is one!) */ /* print compression statistics, and the new name (if there is one!) */
static void static void
print_verbage(const char *file, const char *nfile, off_t usize, off_t gsize) print_verbage(const char *file, const char *nfile, off_t usize, off_t gsize)
@ -2167,7 +2050,6 @@ print_test(const char *file, int ok)
strlen(file) < 7 ? "\t\t" : "\t", ok ? "OK" : "NOT OK"); strlen(file) < 7 ? "\t\t" : "\t", ok ? "OK" : "NOT OK");
fflush(stderr); fflush(stderr);
} }
#endif
/* print a file's info ala --list */ /* print a file's info ala --list */
/* eg: /* eg:
@ -2178,17 +2060,13 @@ static void
print_list(int fd, off_t out, const char *outfile, time_t ts) print_list(int fd, off_t out, const char *outfile, time_t ts)
{ {
static int first = 1; static int first = 1;
#ifndef SMALL
static off_t in_tot, out_tot; static off_t in_tot, out_tot;
uint32_t crc = 0; uint32_t crc = 0;
#endif
off_t in = 0, rv; off_t in = 0, rv;
if (first) { if (first) {
#ifndef SMALL
if (vflag) if (vflag)
printf("method crc date time "); printf("method crc date time ");
#endif
if (qflag == 0) if (qflag == 0)
printf(" compressed uncompressed " printf(" compressed uncompressed "
"ratio uncompressed_name\n"); "ratio uncompressed_name\n");
@ -2196,12 +2074,10 @@ print_list(int fd, off_t out, const char *outfile, time_t ts)
first = 0; first = 0;
/* print totals? */ /* print totals? */
#ifndef SMALL
if (fd == -1) { if (fd == -1) {
in = in_tot; in = in_tot;
out = out_tot; out = out_tot;
} else } else
#endif
{ {
/* read the last 4 bytes - this is the uncompressed size */ /* read the last 4 bytes - this is the uncompressed size */
rv = lseek(fd, (off_t)(-8), SEEK_END); rv = lseek(fd, (off_t)(-8), SEEK_END);
@ -2218,14 +2094,11 @@ print_list(int fd, off_t out, const char *outfile, time_t ts)
else { else {
usize = le32dec(&buf[4]); usize = le32dec(&buf[4]);
in = (off_t)usize; in = (off_t)usize;
#ifndef SMALL
crc = le32dec(&buf[0]); crc = le32dec(&buf[0]);
#endif
} }
} }
} }
#ifndef SMALL
if (vflag && fd == -1) if (vflag && fd == -1)
printf(" "); printf(" ");
else if (vflag) { else if (vflag) {
@ -2238,9 +2111,6 @@ print_list(int fd, off_t out, const char *outfile, time_t ts)
} }
in_tot += in; in_tot += in;
out_tot += out; out_tot += out;
#else
(void)&ts; /* XXX */
#endif
print_list_out(out, in, outfile); print_list_out(out, in, outfile);
} }
@ -2259,9 +2129,6 @@ usage(void)
fprintf(stderr, "%s\n", gzip_version); fprintf(stderr, "%s\n", gzip_version);
fprintf(stderr, fprintf(stderr,
#ifdef SMALL
"usage: %s [-" OPT_LIST "] [<file> [<file> ...]]\n",
#else
"usage: %s [-123456789acdfhklLNnqrtVv] [-S .suffix] [<file> [<file> ...]]\n" "usage: %s [-123456789acdfhklLNnqrtVv] [-S .suffix] [<file> [<file> ...]]\n"
" -1 --fast fastest (worst) compression\n" " -1 --fast fastest (worst) compression\n"
" -2 .. -8 set compression level\n" " -2 .. -8 set compression level\n"
@ -2283,12 +2150,10 @@ usage(void)
" -t --test test compressed file\n" " -t --test test compressed file\n"
" -V --version display program version\n" " -V --version display program version\n"
" -v --verbose print extra statistics\n", " -v --verbose print extra statistics\n",
#endif
getprogname()); getprogname());
exit(0); exit(0);
} }
#ifndef SMALL
/* display the license information of FreeBSD gzip */ /* display the license information of FreeBSD gzip */
static void static void
display_license(void) display_license(void)
@ -2298,7 +2163,6 @@ display_license(void)
fprintf(stderr, "%s\n", gzip_copyright); fprintf(stderr, "%s\n", gzip_copyright);
exit(0); exit(0);
} }
#endif
/* display the version of NetBSD gzip */ /* display the version of NetBSD gzip */
static void static void