Remove remaining NETBSD uppercase references
This commit is contained in:
parent
5188a03964
commit
d8ef58adf3
|
|
@ -1,5 +1,3 @@
|
|||
# $NetBSD: Makefile,v 1.18 2013/11/13 11:12:24 pettai Exp $
|
||||
|
||||
USE_FORT?= yes # data-driven bugs?
|
||||
|
||||
PROG= gzip
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/sh -
|
||||
#
|
||||
# $NetBSD: gzexe,v 1.3 2004/05/01 08:22:41 wiz Exp $
|
||||
#
|
||||
# $OpenBSD: gzexe,v 1.3 2003/08/05 18:22:17 deraadt Exp $
|
||||
#
|
||||
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
.\" $NetBSD: gzexe.1,v 1.3 2003/12/28 12:49:41 wiz Exp $
|
||||
.\" $OpenBSD: gzexe.1,v 1.1 2003/07/31 07:32:47 otto Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
.\" $NetBSD: gzip.1,v 1.25 2015/04/06 21:41:17 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1997, 2003, 2004 Matthew R. Green
|
||||
.\" All rights reserved.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/* $NetBSD: gzip.c,v 1.108 2015/04/15 02:29:12 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997, 1998, 2003, 2004, 2006 Matthew R. Green
|
||||
|
|
@ -30,7 +29,6 @@
|
|||
#ifndef lint
|
||||
__COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006\
|
||||
Matthew R. Green. All rights reserved.");
|
||||
__RCSID("$NetBSD: gzip.c,v 1.108 2015/04/15 02:29:12 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
|
|
@ -50,20 +48,20 @@ __RCSID("$NetBSD: gzip.c,v 1.108 2015/04/15 02:29:12 christos Exp $");
|
|||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <zlib.h>
|
||||
#include <fts.h>
|
||||
#include <getopt.h>
|
||||
#include <inttypes.h>
|
||||
#include <libgen.h>
|
||||
#include <stdarg.h>
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#ifndef PRIdOFF
|
||||
#define PRIdOFF PRId64
|
||||
|
|
@ -137,12 +135,8 @@ static suffixes_t suffixes[] = {
|
|||
#define SUFFIX(Z, N) {Z, sizeof Z - 1, N}
|
||||
SUFFIX(GZ_SUFFIX, ""), /* Overwritten by -S .xxx */
|
||||
#ifndef SMALL
|
||||
SUFFIX(GZ_SUFFIX, ""),
|
||||
SUFFIX(".z", ""),
|
||||
SUFFIX("-gz", ""),
|
||||
SUFFIX("-z", ""),
|
||||
SUFFIX("_z", ""),
|
||||
SUFFIX(".taz", ".tar"),
|
||||
SUFFIX(GZ_SUFFIX, ""), SUFFIX(".z", ""), SUFFIX("-gz", ""),
|
||||
SUFFIX("-z", ""), SUFFIX("_z", ""), SUFFIX(".taz", ".tar"),
|
||||
SUFFIX(".tgz", ".tar"),
|
||||
#ifndef NO_BZIP2_SUPPORT
|
||||
SUFFIX(BZ2_SUFFIX, ""),
|
||||
|
|
@ -160,7 +154,7 @@ static suffixes_t suffixes[] = {
|
|||
#define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
|
||||
#define SUFFIX_MAXLEN 30
|
||||
|
||||
static const char gzip_version[] = "NetBSD gzip 20150113";
|
||||
static const char gzip_version[] = "gzip 20150113";
|
||||
|
||||
static int cflag; /* stdout mode */
|
||||
static int dflag; /* decompress mode */
|
||||
|
|
@ -241,42 +235,40 @@ static off_t unxz(int, int, char *, size_t, off_t *);
|
|||
#endif
|
||||
|
||||
#ifdef SMALL
|
||||
#define getopt_long(a,b,c,d,e) getopt(a,b,c)
|
||||
#define getopt_long(a, b, c, d, e) getopt(a, b, c)
|
||||
#else
|
||||
static const struct option longopts[] = {
|
||||
{ "stdout", no_argument, 0, 'c' },
|
||||
{ "to-stdout", no_argument, 0, 'c' },
|
||||
{ "decompress", no_argument, 0, 'd' },
|
||||
{ "uncompress", no_argument, 0, 'd' },
|
||||
{ "force", no_argument, 0, 'f' },
|
||||
{ "help", no_argument, 0, 'h' },
|
||||
{ "keep", no_argument, 0, 'k' },
|
||||
{ "list", no_argument, 0, 'l' },
|
||||
{ "no-name", no_argument, 0, 'n' },
|
||||
{ "name", no_argument, 0, 'N' },
|
||||
{ "quiet", no_argument, 0, 'q' },
|
||||
{ "recursive", no_argument, 0, 'r' },
|
||||
{ "suffix", required_argument, 0, 'S' },
|
||||
{ "test", no_argument, 0, 't' },
|
||||
{ "verbose", no_argument, 0, 'v' },
|
||||
{ "version", no_argument, 0, 'V' },
|
||||
{ "fast", no_argument, 0, '1' },
|
||||
{ "best", no_argument, 0, '9' },
|
||||
{"stdout", no_argument, 0, 'c'},
|
||||
{"to-stdout", no_argument, 0, 'c'},
|
||||
{"decompress", no_argument, 0, 'd'},
|
||||
{"uncompress", no_argument, 0, 'd'},
|
||||
{"force", no_argument, 0, 'f'},
|
||||
{"help", no_argument, 0, 'h'},
|
||||
{"keep", no_argument, 0, 'k'},
|
||||
{"list", no_argument, 0, 'l'},
|
||||
{"no-name", no_argument, 0, 'n'},
|
||||
{"name", no_argument, 0, 'N'},
|
||||
{"quiet", no_argument, 0, 'q'},
|
||||
{"recursive", no_argument, 0, 'r'},
|
||||
{"suffix", required_argument, 0, 'S'},
|
||||
{"test", no_argument, 0, 't'},
|
||||
{"verbose", no_argument, 0, 'v'},
|
||||
{"version", no_argument, 0, 'V'},
|
||||
{"fast", no_argument, 0, '1'},
|
||||
{"best", no_argument, 0, '9'},
|
||||
#if 0
|
||||
/*
|
||||
* This is what else GNU gzip implements. --ascii isn't useful
|
||||
* on NetBSD, and I don't care to have a --license.
|
||||
* and I don't care to have a --license.
|
||||
*/
|
||||
{ "ascii", no_argument, 0, 'a' },
|
||||
{ "license", no_argument, 0, 'L' },
|
||||
#endif
|
||||
{ NULL, no_argument, 0, 0 },
|
||||
{NULL, no_argument, 0, 0},
|
||||
};
|
||||
#endif
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int main(int argc, char **argv) {
|
||||
const char *progname = getprogname();
|
||||
#ifndef SMALL
|
||||
char *gzip;
|
||||
|
|
@ -297,8 +289,7 @@ main(int argc, char **argv)
|
|||
*/
|
||||
if (strcmp(progname, "gunzip") == 0)
|
||||
dflag = 1;
|
||||
else if (strcmp(progname, "zcat") == 0 ||
|
||||
strcmp(progname, "gzcat") == 0)
|
||||
else if (strcmp(progname, "zcat") == 0 || strcmp(progname, "gzcat") == 0)
|
||||
dflag = cflag = 1;
|
||||
|
||||
#ifdef SMALL
|
||||
|
|
@ -309,9 +300,15 @@ main(int argc, char **argv)
|
|||
|
||||
while ((ch = getopt_long(argc, argv, OPT_LIST, longopts, NULL)) != -1) {
|
||||
switch (ch) {
|
||||
case '1': case '2': case '3':
|
||||
case '4': case '5': case '6':
|
||||
case '7': case '8': case '9':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
numflag = ch - '0';
|
||||
break;
|
||||
case 'c':
|
||||
|
|
@ -395,9 +392,7 @@ main(int argc, char **argv)
|
|||
}
|
||||
|
||||
/* maybe print a warning */
|
||||
void
|
||||
maybe_warn(const char *fmt, ...)
|
||||
{
|
||||
void maybe_warn(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
if (qflag == 0) {
|
||||
|
|
@ -410,9 +405,7 @@ maybe_warn(const char *fmt, ...)
|
|||
}
|
||||
|
||||
/* ... without an errno. */
|
||||
void
|
||||
maybe_warnx(const char *fmt, ...)
|
||||
{
|
||||
void maybe_warnx(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
if (qflag == 0) {
|
||||
|
|
@ -425,9 +418,7 @@ maybe_warnx(const char *fmt, ...)
|
|||
}
|
||||
|
||||
/* maybe print an error */
|
||||
void
|
||||
maybe_err(const char *fmt, ...)
|
||||
{
|
||||
void maybe_err(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
if (qflag == 0) {
|
||||
|
|
@ -441,9 +432,7 @@ maybe_err(const char *fmt, ...)
|
|||
#if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT) || \
|
||||
!defined(NO_XZ_SUPPORT)
|
||||
/* ... without an errno. */
|
||||
void
|
||||
maybe_errx(const char *fmt, ...)
|
||||
{
|
||||
void maybe_errx(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
if (qflag == 0) {
|
||||
|
|
@ -457,9 +446,7 @@ maybe_errx(const char *fmt, ...)
|
|||
|
||||
#ifndef SMALL
|
||||
/* split up $GZIP and prepend it to the argument list */
|
||||
static void
|
||||
prepend_gzip(char *gzip, int *argc, char ***argv)
|
||||
{
|
||||
static void prepend_gzip(char *gzip, int *argc, char ***argv) {
|
||||
char *s, **nargv, **ac;
|
||||
int nenvarg = 0, i;
|
||||
|
||||
|
|
@ -522,9 +509,8 @@ copy_done:
|
|||
#endif
|
||||
|
||||
/* compress input to output. Return bytes read, -1 on error */
|
||||
static off_t
|
||||
gz_compress(int in, int out, off_t *gsizep, const char *origname, uint32_t mtime)
|
||||
{
|
||||
static off_t gz_compress(int in, int out, off_t *gsizep, const char *origname,
|
||||
uint32_t mtime) {
|
||||
z_stream z;
|
||||
char *outbufp, *inbufp;
|
||||
off_t in_tot = 0, out_tot = 0;
|
||||
|
|
@ -532,9 +518,8 @@ gz_compress(int in, int out, off_t *gsizep, const char *origname, uint32_t mtime
|
|||
int i, error;
|
||||
uLong crc;
|
||||
#ifdef SMALL
|
||||
static char header[] = { GZIP_MAGIC0, GZIP_MAGIC1, Z_DEFLATED, 0,
|
||||
0, 0, 0, 0,
|
||||
0, OS_CODE };
|
||||
static char header[] = {GZIP_MAGIC0, GZIP_MAGIC1, Z_DEFLATED, 0, 0,
|
||||
0, 0, 0, 0, OS_CODE};
|
||||
#endif
|
||||
|
||||
outbufp = malloc(BUFLEN);
|
||||
|
|
@ -558,14 +543,12 @@ gz_compress(int in, int out, off_t *gsizep, const char *origname, uint32_t mtime
|
|||
origname = "";
|
||||
}
|
||||
|
||||
i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c%c%c%s",
|
||||
GZIP_MAGIC0, GZIP_MAGIC1, Z_DEFLATED,
|
||||
*origname ? ORIG_NAME : 0,
|
||||
mtime & 0xff,
|
||||
(mtime >> 8) & 0xff,
|
||||
(mtime >> 16) & 0xff,
|
||||
(mtime >> 24) & 0xff,
|
||||
numflag == 1 ? 4 : numflag == 9 ? 2 : 0,
|
||||
i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c%c%c%s", GZIP_MAGIC0,
|
||||
GZIP_MAGIC1, Z_DEFLATED, *origname ? ORIG_NAME : 0, mtime & 0xff,
|
||||
(mtime >> 8) & 0xff, (mtime >> 16) & 0xff, (mtime >> 24) & 0xff,
|
||||
numflag == 1 ? 4
|
||||
: numflag == 9 ? 2
|
||||
: 0,
|
||||
OS_CODE, origname);
|
||||
if (i >= BUFLEN)
|
||||
/* this need PATH_MAX > BUFLEN ... */
|
||||
|
|
@ -577,8 +560,8 @@ gz_compress(int in, int out, off_t *gsizep, const char *origname, uint32_t mtime
|
|||
z.next_out = (unsigned char *)outbufp + i;
|
||||
z.avail_out = BUFLEN - i;
|
||||
|
||||
error = deflateInit2(&z, numflag, Z_DEFLATED,
|
||||
(-MAX_WBITS), 8, Z_DEFAULT_STRATEGY);
|
||||
error = deflateInit2(&z, numflag, Z_DEFLATED, (-MAX_WBITS), 8,
|
||||
Z_DEFAULT_STRATEGY);
|
||||
if (error != Z_OK) {
|
||||
maybe_warnx("deflateInit2 failed");
|
||||
in_tot = -1;
|
||||
|
|
@ -657,14 +640,10 @@ gz_compress(int in, int out, off_t *gsizep, const char *origname, uint32_t mtime
|
|||
goto out;
|
||||
}
|
||||
|
||||
i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c",
|
||||
(int)crc & 0xff,
|
||||
(int)(crc >> 8) & 0xff,
|
||||
(int)(crc >> 16) & 0xff,
|
||||
(int)(crc >> 24) & 0xff,
|
||||
(int)in_tot & 0xff,
|
||||
(int)(in_tot >> 8) & 0xff,
|
||||
(int)(in_tot >> 16) & 0xff,
|
||||
i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c", (int)crc & 0xff,
|
||||
(int)(crc >> 8) & 0xff, (int)(crc >> 16) & 0xff,
|
||||
(int)(crc >> 24) & 0xff, (int)in_tot & 0xff,
|
||||
(int)(in_tot >> 8) & 0xff, (int)(in_tot >> 16) & 0xff,
|
||||
(int)(in_tot >> 24) & 0xff);
|
||||
if (i != 8)
|
||||
maybe_err("snprintf");
|
||||
|
|
@ -693,10 +672,8 @@ out:
|
|||
* uncompressed size written, and put the compressed sized read
|
||||
* into `*gsizep'.
|
||||
*/
|
||||
static off_t
|
||||
gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
|
||||
const char *filename)
|
||||
{
|
||||
static off_t gz_uncompress(int in, int out, char *pre, size_t prelen,
|
||||
off_t *gsizep, const char *filename) {
|
||||
z_stream z;
|
||||
char *outbufp, *inbufp;
|
||||
off_t out_tot = -1, in_tot = 0;
|
||||
|
|
@ -725,7 +702,11 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
|
|||
ssize_t wr;
|
||||
int needmore = 0;
|
||||
|
||||
#define ADVANCE() { z.next_in++; z.avail_in--; }
|
||||
#define ADVANCE() \
|
||||
{ \
|
||||
z.next_in++; \
|
||||
z.avail_in--; \
|
||||
}
|
||||
|
||||
if ((outbufp = malloc(BUFLEN)) == NULL) {
|
||||
maybe_err("malloc failed");
|
||||
|
|
@ -756,8 +737,7 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
|
|||
memmove(inbufp, z.next_in, z.avail_in);
|
||||
}
|
||||
z.next_in = (unsigned char *)inbufp;
|
||||
in_size = read(in, z.next_in + z.avail_in,
|
||||
BUFLEN - z.avail_in);
|
||||
in_size = read(in, z.next_in + z.avail_in, BUFLEN - z.avail_in);
|
||||
|
||||
if (in_size == -1) {
|
||||
maybe_warn("failed to read stdin");
|
||||
|
|
@ -773,8 +753,7 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
|
|||
}
|
||||
if (z.avail_in == 0) {
|
||||
if (done_reading && state != GZSTATE_MAGIC0) {
|
||||
maybe_warnx("%s: unexpected end of file",
|
||||
filename);
|
||||
maybe_warnx("%s: unexpected end of file", filename);
|
||||
goto stop_and_fail;
|
||||
}
|
||||
goto stop;
|
||||
|
|
@ -784,7 +763,8 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
|
|||
if (*z.next_in != GZIP_MAGIC0) {
|
||||
if (in_tot > 0) {
|
||||
maybe_warnx("%s: trailing garbage "
|
||||
"ignored", filename);
|
||||
"ignored",
|
||||
filename);
|
||||
goto stop;
|
||||
}
|
||||
maybe_warnx("input not gziped (MAGIC0)");
|
||||
|
|
@ -797,8 +777,7 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
|
|||
break;
|
||||
|
||||
case GZSTATE_MAGIC1:
|
||||
if (*z.next_in != GZIP_MAGIC1 &&
|
||||
*z.next_in != GZIP_OMAGIC1) {
|
||||
if (*z.next_in != GZIP_MAGIC1 && *z.next_in != GZIP_OMAGIC1) {
|
||||
maybe_warnx("input not gziped (MAGIC1)");
|
||||
goto stop_and_fail;
|
||||
}
|
||||
|
|
@ -924,8 +903,7 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
|
|||
goto stop_and_fail;
|
||||
|
||||
default:
|
||||
maybe_warn("unknown error from inflate(): %d",
|
||||
error);
|
||||
maybe_warn("unknown error from inflate(): %d", error);
|
||||
}
|
||||
wr = BUFLEN - z.avail_out;
|
||||
|
||||
|
|
@ -954,8 +932,7 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
|
|||
z.avail_out = BUFLEN;
|
||||
|
||||
break;
|
||||
case GZSTATE_CRC:
|
||||
{
|
||||
case GZSTATE_CRC: {
|
||||
uLong origcrc;
|
||||
|
||||
if (z.avail_in < 4) {
|
||||
|
|
@ -985,8 +962,7 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
|
|||
}
|
||||
state++;
|
||||
break;
|
||||
case GZSTATE_LEN:
|
||||
{
|
||||
case GZSTATE_LEN: {
|
||||
uLong origlen;
|
||||
|
||||
if (z.avail_in < 4) {
|
||||
|
|
@ -1020,9 +996,9 @@ gz_uncompress(int in, int out, char *pre, size_t prelen, off_t *gsizep,
|
|||
break;
|
||||
}
|
||||
continue;
|
||||
stop_and_fail:
|
||||
stop_and_fail:
|
||||
out_tot = -1;
|
||||
stop:
|
||||
stop:
|
||||
break;
|
||||
}
|
||||
if (state > GZSTATE_INIT)
|
||||
|
|
@ -1042,9 +1018,7 @@ out2:
|
|||
* set the owner, mode, flags & utimes using the given file descriptor.
|
||||
* file is only used in possible warning messages.
|
||||
*/
|
||||
static void
|
||||
copymodes(int fd, const struct stat *sbp, const char *file)
|
||||
{
|
||||
static void copymodes(int fd, const struct stat *sbp, const char *file) {
|
||||
struct timeval times[2];
|
||||
struct stat sb;
|
||||
|
||||
|
|
@ -1065,7 +1039,7 @@ copymodes(int fd, const struct stat *sbp, const char *file)
|
|||
if (fchown(fd, sb.st_uid, sb.st_gid) < 0) {
|
||||
if (errno != EPERM)
|
||||
maybe_warn("couldn't fchown: %s", file);
|
||||
sb.st_mode &= ~(S_ISUID|S_ISGID);
|
||||
sb.st_mode &= ~(S_ISUID | S_ISGID);
|
||||
}
|
||||
|
||||
/* we only allow set-id and the 9 normal permission bits */
|
||||
|
|
@ -1087,17 +1061,14 @@ copymodes(int fd, const struct stat *sbp, const char *file)
|
|||
#endif
|
||||
|
||||
/* what sort of file is this? */
|
||||
static enum filetype
|
||||
file_gettype(u_char *buf)
|
||||
{
|
||||
static enum filetype file_gettype(u_char *buf) {
|
||||
|
||||
if (buf[0] == GZIP_MAGIC0 &&
|
||||
(buf[1] == GZIP_MAGIC1 || buf[1] == GZIP_OMAGIC1))
|
||||
return FT_GZIP;
|
||||
else
|
||||
#ifndef NO_BZIP2_SUPPORT
|
||||
if (memcmp(buf, BZIP2_MAGIC, 3) == 0 &&
|
||||
buf[3] >= '0' && buf[3] <= '9')
|
||||
if (memcmp(buf, BZIP2_MAGIC, 3) == 0 && buf[3] >= '0' && buf[3] <= '9')
|
||||
return FT_BZIP2;
|
||||
else
|
||||
#endif
|
||||
|
|
@ -1121,9 +1092,7 @@ file_gettype(u_char *buf)
|
|||
|
||||
#ifndef SMALL
|
||||
/* check the outfile is OK. */
|
||||
static int
|
||||
check_outfile(const char *outfile)
|
||||
{
|
||||
static int check_outfile(const char *outfile) {
|
||||
struct stat sb;
|
||||
int ok = 1;
|
||||
|
||||
|
|
@ -1131,10 +1100,12 @@ check_outfile(const char *outfile)
|
|||
if (fflag)
|
||||
unlink(outfile);
|
||||
else if (isatty(STDIN_FILENO)) {
|
||||
char ans[10] = { 'n', '\0' }; /* default */
|
||||
char ans[10] = {'n', '\0'}; /* default */
|
||||
|
||||
fprintf(stderr, "%s already exists -- do you wish to "
|
||||
"overwrite (y or n)? " , outfile);
|
||||
fprintf(stderr,
|
||||
"%s already exists -- do you wish to "
|
||||
"overwrite (y or n)? ",
|
||||
outfile);
|
||||
(void)fgets(ans, sizeof(ans) - 1, stdin);
|
||||
if (ans[0] != 'y' && ans[0] != 'Y') {
|
||||
fprintf(stderr, "\tnot overwriting\n");
|
||||
|
|
@ -1149,9 +1120,7 @@ check_outfile(const char *outfile)
|
|||
return ok;
|
||||
}
|
||||
|
||||
static void
|
||||
unlink_input(const char *file, const struct stat *sb)
|
||||
{
|
||||
static void unlink_input(const char *file, const struct stat *sb) {
|
||||
struct stat nsb;
|
||||
|
||||
if (kflag)
|
||||
|
|
@ -1166,9 +1135,7 @@ unlink_input(const char *file, const struct stat *sb)
|
|||
}
|
||||
#endif
|
||||
|
||||
static const suffixes_t *
|
||||
check_suffix(char *file, int xlate)
|
||||
{
|
||||
static const suffixes_t *check_suffix(char *file, int xlate) {
|
||||
const suffixes_t *s;
|
||||
int len = strlen(file);
|
||||
char *sp;
|
||||
|
|
@ -1191,9 +1158,7 @@ check_suffix(char *file, int xlate)
|
|||
* compress the given file: create a corresponding .gz file and remove the
|
||||
* original.
|
||||
*/
|
||||
static off_t
|
||||
file_compress(char *file, char *outfile, size_t outsize)
|
||||
{
|
||||
static off_t file_compress(char *file, char *outfile, size_t outsize) {
|
||||
int in;
|
||||
int out;
|
||||
off_t size, insize;
|
||||
|
|
@ -1213,27 +1178,25 @@ file_compress(char *file, char *outfile, size_t outsize)
|
|||
if (fstat(in, &isb) == 0) {
|
||||
if (isb.st_nlink > 1 && fflag == 0) {
|
||||
maybe_warnx("%s has %d other link%s -- "
|
||||
"skipping", file, isb.st_nlink - 1,
|
||||
isb.st_nlink == 1 ? "" : "s");
|
||||
"skipping",
|
||||
file, isb.st_nlink - 1, isb.st_nlink == 1 ? "" : "s");
|
||||
close(in);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (fflag == 0 && (suff = check_suffix(file, 0))
|
||||
&& suff->zipped[0] != 0) {
|
||||
maybe_warnx("%s already has %s suffix -- unchanged",
|
||||
file, suff->zipped);
|
||||
if (fflag == 0 && (suff = check_suffix(file, 0)) && suff->zipped[0] != 0) {
|
||||
maybe_warnx("%s already has %s suffix -- unchanged", file, suff->zipped);
|
||||
close(in);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Add (usually) .gz to filename */
|
||||
if ((size_t)snprintf(outfile, outsize, "%s%s",
|
||||
file, suffixes[0].zipped) >= outsize)
|
||||
memcpy(outfile + outsize - suffixes[0].ziplen - 1,
|
||||
suffixes[0].zipped, suffixes[0].ziplen + 1);
|
||||
if ((size_t)snprintf(outfile, outsize, "%s%s", file, suffixes[0].zipped) >=
|
||||
outsize)
|
||||
memcpy(outfile + outsize - suffixes[0].ziplen - 1, suffixes[0].zipped,
|
||||
suffixes[0].ziplen + 1);
|
||||
|
||||
#ifndef SMALL
|
||||
if (check_outfile(outfile) == 0) {
|
||||
|
|
@ -1274,8 +1237,8 @@ file_compress(char *file, char *outfile, size_t outsize)
|
|||
}
|
||||
|
||||
if (osb.st_size != size) {
|
||||
maybe_warnx("output file: %s wrong size (%" PRIdOFF
|
||||
" != %" PRIdOFF "), deleting",
|
||||
maybe_warnx("output file: %s wrong size (%" PRIdOFF " != %" PRIdOFF
|
||||
"), deleting",
|
||||
outfile, osb.st_size, size);
|
||||
goto bad_outfile;
|
||||
}
|
||||
|
|
@ -1290,7 +1253,7 @@ file_compress(char *file, char *outfile, size_t outsize)
|
|||
return size;
|
||||
|
||||
#ifndef SMALL
|
||||
bad_outfile:
|
||||
bad_outfile:
|
||||
if (close(out) == -1)
|
||||
maybe_warn("couldn't close output");
|
||||
|
||||
|
|
@ -1301,9 +1264,7 @@ file_compress(char *file, char *outfile, size_t outsize)
|
|||
}
|
||||
|
||||
/* uncompress the given file and remove the original */
|
||||
static off_t
|
||||
file_uncompress(char *file, char *outfile, size_t outsize)
|
||||
{
|
||||
static off_t file_uncompress(char *file, char *outfile, size_t outsize) {
|
||||
struct stat isb, osb;
|
||||
off_t size;
|
||||
ssize_t rbytes;
|
||||
|
|
@ -1392,9 +1353,8 @@ file_uncompress(char *file, char *outfile, size_t outsize)
|
|||
dp = file;
|
||||
else
|
||||
dp++;
|
||||
snprintf(outfile, outsize, "%.*s%.*s",
|
||||
(int) (dp - file),
|
||||
file, (int) rbytes, nf);
|
||||
snprintf(outfile, outsize, "%.*s%.*s", (int)(dp - file), file,
|
||||
(int)rbytes, nf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1406,8 +1366,7 @@ file_uncompress(char *file, char *outfile, size_t outsize)
|
|||
goto lose;
|
||||
#ifndef SMALL
|
||||
if (isb.st_nlink > 1 && lflag == 0 && fflag == 0) {
|
||||
maybe_warnx("%s has %d other links -- skipping",
|
||||
file, isb.st_nlink - 1);
|
||||
maybe_warnx("%s has %d other links -- skipping", file, isb.st_nlink - 1);
|
||||
goto lose;
|
||||
}
|
||||
if (nflag == 0 && timestamp)
|
||||
|
|
@ -1418,7 +1377,7 @@ file_uncompress(char *file, char *outfile, size_t outsize)
|
|||
}
|
||||
|
||||
if (cflag == 0 && lflag == 0) {
|
||||
zfd = open(outfile, O_WRONLY|O_CREAT|O_EXCL, 0600);
|
||||
zfd = open(outfile, O_WRONLY | O_CREAT | O_EXCL, 0600);
|
||||
if (zfd == STDOUT_FILENO) {
|
||||
/* We won't close STDOUT_FILENO later... */
|
||||
zfd = dup(zfd);
|
||||
|
|
@ -1554,19 +1513,17 @@ file_uncompress(char *file, char *outfile, size_t outsize)
|
|||
|
||||
ofd = open(outfile, O_RDWR, 0);
|
||||
if (ofd == -1) {
|
||||
maybe_warn("couldn't open (leaving original): %s",
|
||||
outfile);
|
||||
maybe_warn("couldn't open (leaving original): %s", outfile);
|
||||
return -1;
|
||||
}
|
||||
if (fstat(ofd, &osb) != 0) {
|
||||
maybe_warn("couldn't stat (leaving original): %s",
|
||||
outfile);
|
||||
maybe_warn("couldn't stat (leaving original): %s", outfile);
|
||||
close(ofd);
|
||||
return -1;
|
||||
}
|
||||
if (osb.st_size != size) {
|
||||
maybe_warnx("stat gave different size: %" PRIdOFF
|
||||
" != %" PRIdOFF " (leaving original)",
|
||||
maybe_warnx("stat gave different size: %" PRIdOFF " != %" PRIdOFF
|
||||
" (leaving original)",
|
||||
size, osb.st_size);
|
||||
close(ofd);
|
||||
unlink(outfile);
|
||||
|
|
@ -1579,9 +1536,9 @@ file_uncompress(char *file, char *outfile, size_t outsize)
|
|||
close(ofd);
|
||||
return size;
|
||||
|
||||
unexpected_EOF:
|
||||
unexpected_EOF:
|
||||
maybe_warnx("%s: unexpected end of file", file);
|
||||
lose:
|
||||
lose:
|
||||
if (fd != -1)
|
||||
close(fd);
|
||||
if (zfd != -1 && zfd != STDOUT_FILENO)
|
||||
|
|
@ -1590,9 +1547,8 @@ file_uncompress(char *file, char *outfile, size_t outsize)
|
|||
}
|
||||
|
||||
#ifndef SMALL
|
||||
static off_t
|
||||
cat_fd(unsigned char * prepend, size_t count, off_t *gsizep, int fd)
|
||||
{
|
||||
static off_t cat_fd(unsigned char *prepend, size_t count, off_t *gsizep,
|
||||
int fd) {
|
||||
char buf[BUFLEN];
|
||||
off_t in_tot;
|
||||
ssize_t w;
|
||||
|
|
@ -1627,9 +1583,7 @@ cat_fd(unsigned char * prepend, size_t count, off_t *gsizep, int fd)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
handle_stdin(void)
|
||||
{
|
||||
static void handle_stdin(void) {
|
||||
unsigned char header1[4];
|
||||
off_t usize, gsize;
|
||||
enum filetype method;
|
||||
|
|
@ -1678,13 +1632,13 @@ handle_stdin(void)
|
|||
break;
|
||||
#endif
|
||||
case FT_GZIP:
|
||||
usize = gz_uncompress(STDIN_FILENO, STDOUT_FILENO,
|
||||
(char *)header1, sizeof header1, &gsize, "(stdin)");
|
||||
usize = gz_uncompress(STDIN_FILENO, STDOUT_FILENO, (char *)header1,
|
||||
sizeof header1, &gsize, "(stdin)");
|
||||
break;
|
||||
#ifndef NO_BZIP2_SUPPORT
|
||||
case FT_BZIP2:
|
||||
usize = unbzip2(STDIN_FILENO, STDOUT_FILENO,
|
||||
(char *)header1, sizeof header1, &gsize);
|
||||
usize = unbzip2(STDIN_FILENO, STDOUT_FILENO, (char *)header1,
|
||||
sizeof header1, &gsize);
|
||||
break;
|
||||
#endif
|
||||
#ifndef NO_COMPRESS_SUPPORT
|
||||
|
|
@ -1694,21 +1648,20 @@ handle_stdin(void)
|
|||
return;
|
||||
}
|
||||
|
||||
usize = zuncompress(in, stdout, (char *)header1,
|
||||
sizeof header1, &gsize);
|
||||
usize = zuncompress(in, stdout, (char *)header1, sizeof header1, &gsize);
|
||||
fclose(in);
|
||||
break;
|
||||
#endif
|
||||
#ifndef NO_PACK_SUPPORT
|
||||
case FT_PACK:
|
||||
usize = unpack(STDIN_FILENO, STDOUT_FILENO,
|
||||
(char *)header1, sizeof header1, &gsize);
|
||||
usize = unpack(STDIN_FILENO, STDOUT_FILENO, (char *)header1, sizeof header1,
|
||||
&gsize);
|
||||
break;
|
||||
#endif
|
||||
#ifndef NO_XZ_SUPPORT
|
||||
case FT_XZ:
|
||||
usize = unxz(STDIN_FILENO, STDOUT_FILENO,
|
||||
(char *)header1, sizeof header1, &gsize);
|
||||
usize = unxz(STDIN_FILENO, STDOUT_FILENO, (char *)header1, sizeof header1,
|
||||
&gsize);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1719,12 +1672,9 @@ handle_stdin(void)
|
|||
if (vflag && tflag)
|
||||
print_test("(stdin)", usize != -1);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
handle_stdout(void)
|
||||
{
|
||||
static void handle_stdout(void) {
|
||||
off_t gsize, usize;
|
||||
struct stat sb;
|
||||
time_t systime;
|
||||
|
|
@ -1768,9 +1718,7 @@ handle_stdout(void)
|
|||
}
|
||||
|
||||
/* do what is asked for, for the path name */
|
||||
static void
|
||||
handle_pathname(char *path)
|
||||
{
|
||||
static void handle_pathname(char *path) {
|
||||
char *opath = path, *s = NULL;
|
||||
ssize_t len;
|
||||
int slen;
|
||||
|
|
@ -1824,9 +1772,7 @@ out:
|
|||
}
|
||||
|
||||
/* compress/decompress a file */
|
||||
static void
|
||||
handle_file(char *file, struct stat *sbp)
|
||||
{
|
||||
static void handle_file(char *file, struct stat *sbp) {
|
||||
off_t usize, gsize;
|
||||
char outfile[PATH_MAX];
|
||||
|
||||
|
|
@ -1847,7 +1793,6 @@ handle_file(char *file, struct stat *sbp)
|
|||
usize = sbp->st_size;
|
||||
}
|
||||
|
||||
|
||||
#ifndef SMALL
|
||||
if (vflag && !tflag)
|
||||
print_verbage(file, (cflag) ? NULL : outfile, usize, gsize);
|
||||
|
|
@ -1856,9 +1801,7 @@ handle_file(char *file, struct stat *sbp)
|
|||
|
||||
#ifndef SMALL
|
||||
/* this is used with -r to recursively descend directories */
|
||||
static void
|
||||
handle_dir(char *dir)
|
||||
{
|
||||
static void handle_dir(char *dir) {
|
||||
char *path_argv[2];
|
||||
FTS *fts;
|
||||
FTSENT *entry;
|
||||
|
|
@ -1872,7 +1815,7 @@ handle_dir(char *dir)
|
|||
}
|
||||
|
||||
while ((entry = fts_read(fts))) {
|
||||
switch(entry->fts_info) {
|
||||
switch (entry->fts_info) {
|
||||
case FTS_D:
|
||||
case FTS_DP:
|
||||
continue;
|
||||
|
|
@ -1891,15 +1834,13 @@ handle_dir(char *dir)
|
|||
#endif
|
||||
|
||||
/* print a ratio - size reduction as a fraction of uncompressed size */
|
||||
static void
|
||||
print_ratio(off_t in, off_t out, FILE *where)
|
||||
{
|
||||
static void print_ratio(off_t in, off_t out, FILE *where) {
|
||||
int percent10; /* 10 * percent */
|
||||
off_t diff;
|
||||
char buff[8];
|
||||
int len;
|
||||
|
||||
diff = in - out/2;
|
||||
diff = in - out / 2;
|
||||
if (diff <= 0)
|
||||
/*
|
||||
* Output is more than double size of input! print -99.9%
|
||||
|
|
@ -1930,12 +1871,10 @@ print_ratio(off_t in, off_t out, FILE *where)
|
|||
|
||||
#ifndef SMALL
|
||||
/* print compression statistics, and the new name (if there is one!) */
|
||||
static void
|
||||
print_verbage(const char *file, const char *nfile, off_t usize, off_t gsize)
|
||||
{
|
||||
static void print_verbage(const char *file, const char *nfile, off_t usize,
|
||||
off_t gsize) {
|
||||
if (file)
|
||||
fprintf(stderr, "%s:%s ", file,
|
||||
strlen(file) < 7 ? "\t\t" : "\t");
|
||||
fprintf(stderr, "%s:%s ", file, strlen(file) < 7 ? "\t\t" : "\t");
|
||||
print_ratio(usize, gsize, stderr);
|
||||
if (nfile)
|
||||
fprintf(stderr, " -- replaced with %s", nfile);
|
||||
|
|
@ -1944,14 +1883,12 @@ print_verbage(const char *file, const char *nfile, off_t usize, off_t gsize)
|
|||
}
|
||||
|
||||
/* print test results */
|
||||
static void
|
||||
print_test(const char *file, int ok)
|
||||
{
|
||||
static void print_test(const char *file, int ok) {
|
||||
|
||||
if (exit_value == 0 && ok == 0)
|
||||
exit_value = 1;
|
||||
fprintf(stderr, "%s:%s %s\n", file,
|
||||
strlen(file) < 7 ? "\t\t" : "\t", ok ? "OK" : "NOT OK");
|
||||
fprintf(stderr, "%s:%s %s\n", file, strlen(file) < 7 ? "\t\t" : "\t",
|
||||
ok ? "OK" : "NOT OK");
|
||||
fflush(stderr);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1961,9 +1898,7 @@ print_test(const char *file, int ok)
|
|||
compressed uncompressed ratio uncompressed_name
|
||||
354841 1679360 78.8% /usr/pkgsrc/distfiles/libglade-2.0.1.tar
|
||||
*/
|
||||
static void
|
||||
print_list(int fd, off_t out, const char *outfile, time_t ts)
|
||||
{
|
||||
static void print_list(int fd, off_t out, const char *outfile, time_t ts) {
|
||||
static int first = 1;
|
||||
#ifndef SMALL
|
||||
static off_t in_tot, out_tot;
|
||||
|
|
@ -2003,12 +1938,10 @@ print_list(int fd, off_t out, const char *outfile, time_t ts)
|
|||
maybe_warnx("read of uncompressed size");
|
||||
|
||||
else {
|
||||
usize = buf[4] | buf[5] << 8 |
|
||||
buf[6] << 16 | buf[7] << 24;
|
||||
usize = buf[4] | buf[5] << 8 | buf[6] << 16 | buf[7] << 24;
|
||||
in = (off_t)usize;
|
||||
#ifndef SMALL
|
||||
crc = buf[0] | buf[1] << 8 |
|
||||
buf[2] << 16 | buf[3] << 24;
|
||||
crc = buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
@ -2023,7 +1956,7 @@ print_list(int fd, off_t out, const char *outfile, time_t ts)
|
|||
/* skip the day, 1/100th second, and year */
|
||||
date += 4;
|
||||
date[12] = 0;
|
||||
printf("%5s %08x %11s ", "defla"/*XXX*/, crc, date);
|
||||
printf("%5s %08x %11s ", "defla" /*XXX*/, crc, date);
|
||||
}
|
||||
in_tot += in;
|
||||
out_tot += out;
|
||||
|
|
@ -2033,10 +1966,8 @@ print_list(int fd, off_t out, const char *outfile, time_t ts)
|
|||
printf(" %s\n", outfile);
|
||||
}
|
||||
|
||||
/* display the usage of NetBSD gzip */
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
/* display the usage of gzip */
|
||||
static void usage(void) {
|
||||
|
||||
fprintf(stderr, "%s\n", gzip_version);
|
||||
fprintf(stderr,
|
||||
|
|
@ -2053,7 +1984,8 @@ usage(void)
|
|||
" -h --help display this help\n"
|
||||
" -k --keep don't delete input files during operation\n"
|
||||
" -l --list list compressed file contents\n"
|
||||
" -N --name save or restore original file name and time stamp\n"
|
||||
" -N --name save or restore original file name and time "
|
||||
"stamp\n"
|
||||
" -n --no-name don't save original file name or time stamp\n"
|
||||
" -q --quiet output no warnings\n"
|
||||
" -r --recursive recursively compress files in directories\n"
|
||||
|
|
@ -2069,10 +2001,8 @@ usage(void)
|
|||
exit(0);
|
||||
}
|
||||
|
||||
/* display the version of NetBSD gzip */
|
||||
static void
|
||||
display_version(void)
|
||||
{
|
||||
/* display the version of gzip */
|
||||
static void display_version(void) {
|
||||
|
||||
fprintf(stderr, "%s\n", gzip_version);
|
||||
exit(0);
|
||||
|
|
@ -2091,11 +2021,9 @@ display_version(void)
|
|||
#include "unxz.c"
|
||||
#endif
|
||||
|
||||
static ssize_t
|
||||
read_retry(int fd, void *buf, size_t sz)
|
||||
{
|
||||
static ssize_t read_retry(int fd, void *buf, size_t sz) {
|
||||
char *cp = buf;
|
||||
size_t left = MIN(sz, (size_t) SSIZE_MAX);
|
||||
size_t left = MIN(sz, (size_t)SSIZE_MAX);
|
||||
|
||||
while (left > 0) {
|
||||
ssize_t ret;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
/* $NetBSD: unbzip2.c,v 1.13 2009/12/05 03:23:37 mrg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2006 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 2006 The Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* This code is derived from software contributed to The Foundation
|
||||
* by Simon Burge.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -16,7 +15,7 @@
|
|||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* THIS SOFTWARE IS PROVIDED BY THE FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
|
|
@ -31,9 +30,8 @@
|
|||
|
||||
/* This file is #included by gzip.c */
|
||||
|
||||
static off_t
|
||||
unbzip2(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
|
||||
{
|
||||
static off_t unbzip2(int in, int out, char *pre, size_t prelen,
|
||||
off_t *bytes_in) {
|
||||
int ret, end_of_file, cold = 0;
|
||||
off_t bytes_out = 0;
|
||||
bz_stream bzs;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/* $FreeBSD: head/usr.bin/gzip/unpack.c 194579 2009-06-21 09:39:43Z delphij $ */
|
||||
/* $NetBSD: unpack.c,v 1.2 2010/11/06 21:42:32 mrg Exp $ */
|
||||
/* $FreeBSD: head/usr.bin/gzip/unpack.c 194579 2009-06-21 09:39:43Z delphij
|
||||
* $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009 Xin LI <delphij@FreeBSD.org>
|
||||
|
|
@ -95,9 +95,7 @@ typedef struct {
|
|||
* We don't zero out pointers here because nobody else would ever
|
||||
* reference the memory block without scrubbing them.
|
||||
*/
|
||||
static void
|
||||
unpack_descriptor_fini(unpack_descriptor_t *unpackd)
|
||||
{
|
||||
static void unpack_descriptor_fini(unpack_descriptor_t *unpackd) {
|
||||
|
||||
free(unpackd->symbolsin);
|
||||
free(unpackd->inodesin);
|
||||
|
|
@ -111,9 +109,8 @@ unpack_descriptor_fini(unpack_descriptor_t *unpackd)
|
|||
/*
|
||||
* Recursively fill the internal node count table
|
||||
*/
|
||||
static void
|
||||
unpackd_fill_inodesin(const unpack_descriptor_t *unpackd, int level)
|
||||
{
|
||||
static void unpackd_fill_inodesin(const unpack_descriptor_t *unpackd,
|
||||
int level) {
|
||||
|
||||
/*
|
||||
* The internal nodes would be 1/2 of total internal nodes and
|
||||
|
|
@ -122,8 +119,8 @@ unpackd_fill_inodesin(const unpack_descriptor_t *unpackd, int level)
|
|||
*/
|
||||
if (level < unpackd->treelevels) {
|
||||
unpackd_fill_inodesin(unpackd, level + 1);
|
||||
unpackd->inodesin[level] = (unpackd->inodesin[level + 1] +
|
||||
unpackd->symbolsin[level + 1]) / 2;
|
||||
unpackd->inodesin[level] =
|
||||
(unpackd->inodesin[level + 1] + unpackd->symbolsin[level + 1]) / 2;
|
||||
} else
|
||||
unpackd->inodesin[level] = 0;
|
||||
}
|
||||
|
|
@ -131,9 +128,7 @@ unpackd_fill_inodesin(const unpack_descriptor_t *unpackd, int level)
|
|||
/*
|
||||
* Update counter for accepted bytes
|
||||
*/
|
||||
static void
|
||||
accepted_bytes(off_t *bytes_in, off_t newbytes)
|
||||
{
|
||||
static void accepted_bytes(off_t *bytes_in, off_t newbytes) {
|
||||
|
||||
if (bytes_in != NULL)
|
||||
(*bytes_in) += newbytes;
|
||||
|
|
@ -145,10 +140,8 @@ accepted_bytes(off_t *bytes_in, off_t newbytes)
|
|||
*
|
||||
* Return value is uncompressed size.
|
||||
*/
|
||||
static void
|
||||
unpack_parse_header(int in, int out, char *pre, size_t prelen, off_t *bytes_in,
|
||||
unpack_descriptor_t *unpackd)
|
||||
{
|
||||
static void unpack_parse_header(int in, int out, char *pre, size_t prelen,
|
||||
off_t *bytes_in, unpack_descriptor_t *unpackd) {
|
||||
unsigned char hdr[PACK_HEADER_LENGTH]; /* buffer for header */
|
||||
ssize_t bytesread; /* Bytes read from the file */
|
||||
int i, j, thisbyte;
|
||||
|
|
@ -183,12 +176,10 @@ unpack_parse_header(int in, int out, char *pre, size_t prelen, off_t *bytes_in,
|
|||
maybe_err("Can not fdopen() output stream");
|
||||
|
||||
/* Allocate for the tables of bounds and the tree itself */
|
||||
unpackd->inodesin =
|
||||
calloc(unpackd->treelevels, sizeof(*(unpackd->inodesin)));
|
||||
unpackd->inodesin = calloc(unpackd->treelevels, sizeof(*(unpackd->inodesin)));
|
||||
unpackd->symbolsin =
|
||||
calloc(unpackd->treelevels, sizeof(*(unpackd->symbolsin)));
|
||||
unpackd->tree =
|
||||
calloc(unpackd->treelevels, (sizeof (*(unpackd->tree))));
|
||||
unpackd->tree = calloc(unpackd->treelevels, (sizeof(*(unpackd->tree))));
|
||||
if (unpackd->inodesin == NULL || unpackd->symbolsin == NULL ||
|
||||
unpackd->tree == NULL)
|
||||
maybe_err("calloc");
|
||||
|
|
@ -246,9 +237,7 @@ unpack_parse_header(int in, int out, char *pre, size_t prelen, off_t *bytes_in,
|
|||
/*
|
||||
* Decode huffman stream, based on the huffman tree.
|
||||
*/
|
||||
static void
|
||||
unpack_decode(const unpack_descriptor_t *unpackd, off_t *bytes_in)
|
||||
{
|
||||
static void unpack_decode(const unpack_descriptor_t *unpackd, off_t *bytes_in) {
|
||||
int thislevel, thiscode, thisbyte, inlevelindex;
|
||||
int i;
|
||||
off_t bytes_out = 0;
|
||||
|
|
@ -278,13 +267,11 @@ unpack_decode(const unpack_descriptor_t *unpackd, off_t *bytes_in)
|
|||
|
||||
/* Did we got a symbol? (referencing leaf node) */
|
||||
if (thiscode >= unpackd->inodesin[thislevel]) {
|
||||
inlevelindex =
|
||||
thiscode - unpackd->inodesin[thislevel];
|
||||
inlevelindex = thiscode - unpackd->inodesin[thislevel];
|
||||
if (inlevelindex > unpackd->symbolsin[thislevel])
|
||||
maybe_errx("File corrupt");
|
||||
|
||||
thissymbol =
|
||||
&(unpackd->tree[thislevel][inlevelindex]);
|
||||
thissymbol = &(unpackd->tree[thislevel][inlevelindex]);
|
||||
if ((thissymbol == unpackd->symbol_eob) &&
|
||||
(bytes_out == unpackd->uncompressed_size))
|
||||
goto finished;
|
||||
|
|
@ -293,7 +280,8 @@ unpack_decode(const unpack_descriptor_t *unpackd, off_t *bytes_in)
|
|||
bytes_out++;
|
||||
|
||||
/* Prepare for next input */
|
||||
thislevel = 0; thiscode = 0;
|
||||
thislevel = 0;
|
||||
thiscode = 0;
|
||||
} else {
|
||||
thislevel++;
|
||||
if (thislevel > unpackd->treelevels)
|
||||
|
|
@ -308,9 +296,8 @@ finished:
|
|||
}
|
||||
|
||||
/* Handler for pack(1)'ed file */
|
||||
static off_t
|
||||
unpack(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
|
||||
{
|
||||
static off_t unpack(int in, int out, char *pre, size_t prelen,
|
||||
off_t *bytes_in) {
|
||||
unpack_descriptor_t unpackd;
|
||||
|
||||
unpack_parse_header(dup(in), dup(out), pre, prelen, bytes_in, &unpackd);
|
||||
|
|
@ -320,4 +307,3 @@ unpack(int in, int out, char *pre, size_t prelen, off_t *bytes_in)
|
|||
/* If we reached here, the unpack was successful */
|
||||
return (unpackd.uncompressed_size);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
/* $NetBSD: unxz.c,v 1.5 2011/09/30 01:32:21 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2011 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 2011 The Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* This code is derived from software contributed to The Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -17,13 +16,13 @@
|
|||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* This product includes software developed by the
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* 4. Neither the name of The Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* THIS SOFTWARE IS PROVIDED BY THE FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
|
|
@ -36,19 +35,16 @@
|
|||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: unxz.c,v 1.5 2011/09/30 01:32:21 christos Exp $");
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <errno.h>
|
||||
#include <lzma.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <lzma.h>
|
||||
|
||||
static off_t
|
||||
unxz(int i, int o, char *pre, size_t prelen, off_t *bytes_in)
|
||||
{
|
||||
static off_t unxz(int i, int o, char *pre, size_t prelen, off_t *bytes_in) {
|
||||
lzma_stream strm = LZMA_STREAM_INIT;
|
||||
static const int flags = LZMA_TELL_UNSUPPORTED_CHECK|LZMA_CONCATENATED;
|
||||
static const int flags = LZMA_TELL_UNSUPPORTED_CHECK | LZMA_CONCATENATED;
|
||||
lzma_ret ret;
|
||||
lzma_action action = LZMA_RUN;
|
||||
off_t bytes_out, bp;
|
||||
|
|
@ -154,7 +150,6 @@ unxz(int i, int o, char *pre, size_t prelen, off_t *bytes_in)
|
|||
break;
|
||||
}
|
||||
maybe_errx("%s", msg);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
#!/bin/sh -
|
||||
#
|
||||
# $NetBSD: zdiff,v 1.5 2010/04/14 20:30:28 joerg Exp $
|
||||
#
|
||||
# $OpenBSD: zdiff,v 1.2 2003/07/29 07:42:44 otto Exp $
|
||||
#
|
||||
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
# Copyright (c) 2010 Joerg Sonnenberger <joerg@NetBSD.org>
|
||||
# Copyright (c) 2010 Joerg Sonnenberger <joerg@example.org>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
.\" $NetBSD: zdiff.1,v 1.5 2010/04/14 19:52:05 wiz Exp $
|
||||
.\" $OpenBSD: zdiff.1,v 1.2 2003/07/13 17:39:14 millert Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
.\" Copyright (c) 2010 Joerg Sonnenberger <joerg@NetBSD.org>
|
||||
.\" Copyright (c) 2010 Joerg Sonnenberger <joerg@example.org>
|
||||
.\"
|
||||
.\" Permission to use, copy, modify, and distribute this software for any
|
||||
.\" purpose with or without fee is hereby granted, provided that the above
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/sh -
|
||||
#
|
||||
# $NetBSD: zforce,v 1.2 2003/12/28 12:43:43 wiz Exp $
|
||||
#
|
||||
# $OpenBSD: zforce,v 1.2 2003/08/05 18:22:17 deraadt Exp $
|
||||
#
|
||||
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
.\" $NetBSD: zforce.1,v 1.2 2003/12/28 12:43:43 wiz Exp $
|
||||
.\" $OpenBSD: zforce.1,v 1.1 2003/07/29 11:50:09 otto Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# $NetBSD: zgrep,v 1.9 2015/07/06 12:05:40 nakayama Exp $
|
||||
#
|
||||
# Copyright (c) 2003 Thomas Klausner.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
.\" $NetBSD: zgrep.1,v 1.3 2008/05/08 15:35:23 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Thomas Klausner.
|
||||
.\"
|
||||
|
|
@ -91,4 +90,4 @@ In case of missing arguments or missing pattern,
|
|||
.Xr zcat 1
|
||||
.Sh AUTHORS
|
||||
.An Thomas Klausner
|
||||
.Aq wiz@NetBSD.org
|
||||
.Aq wiz@example.org
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/sh -
|
||||
#
|
||||
# $NetBSD: zmore,v 1.5 2013/12/06 13:33:15 pettai Exp $
|
||||
#
|
||||
# $OpenBSD: zmore,v 1.6 2008/08/20 09:22:02 mpf Exp $
|
||||
#
|
||||
# Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
.\" $NetBSD: zmore.1,v 1.4 2013/11/12 21:58:37 pettai Exp $
|
||||
.\" $OpenBSD: zmore.1,v 1.10 2009/08/16 09:41:08 sobrado Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#!/bin/ksh -
|
||||
#
|
||||
# $NetBSD: znew,v 1.3 2008/04/27 09:07:13 nakayama Exp $
|
||||
#
|
||||
# $OpenBSD: znew,v 1.2 2003/08/05 18:22:17 deraadt Exp $
|
||||
#
|
||||
# Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
.\" $NetBSD: znew.1,v 1.2 2003/12/28 12:43:43 wiz Exp $
|
||||
.\" $OpenBSD: znew.1,v 1.1 2003/08/02 20:52:50 otto Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2003 Otto Moerbeek <otto@drijf.net>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/* $NetBSD: zuncompress.c,v 1.11 2011/08/16 13:55:02 joerg Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1985, 1986, 1992, 1993
|
||||
|
|
@ -32,7 +31,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: NetBSD: zopen.c,v 1.8 2003/08/07 11:13:29 agc Exp
|
||||
* from: zopen.c,v 1.8 2003/08/07 11:13:29 agc Exp
|
||||
*/
|
||||
|
||||
/* This file is #included by gzip.c */
|
||||
|
|
@ -63,18 +62,16 @@ static int zread(void *, char *, int);
|
|||
#define FIRST 257 /* First free entry. */
|
||||
#define CLEAR 256 /* Table clear output code. */
|
||||
|
||||
|
||||
#define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
|
||||
|
||||
typedef long code_int;
|
||||
typedef long count_int;
|
||||
typedef u_char char_type;
|
||||
|
||||
static char_type magic_header[] =
|
||||
{'\037', '\235'}; /* 1F 9D */
|
||||
static char_type magic_header[] = {'\037', '\235'}; /* 1F 9D */
|
||||
|
||||
static char_type rmask[9] =
|
||||
{0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
|
||||
static char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f,
|
||||
0x1f, 0x3f, 0x7f, 0xff};
|
||||
|
||||
/* XXX zuncompress global */
|
||||
off_t total_compressed_bytes;
|
||||
|
|
@ -84,15 +81,13 @@ char *compressed_pre;
|
|||
struct s_zstate {
|
||||
FILE *zs_fp; /* File stream for I/O */
|
||||
char zs_mode; /* r or w */
|
||||
enum {
|
||||
S_START, S_MIDDLE, S_EOF
|
||||
} zs_state; /* State of computation */
|
||||
enum { S_START, S_MIDDLE, S_EOF } zs_state; /* State of computation */
|
||||
int zs_n_bits; /* Number of bits/code. */
|
||||
int zs_maxbits; /* User settable max # bits/code. */
|
||||
code_int zs_maxcode; /* Maximum code, given n_bits. */
|
||||
code_int zs_maxmaxcode; /* Should NEVER generate this code. */
|
||||
count_int zs_htab [HSIZE];
|
||||
u_short zs_codetab [HSIZE];
|
||||
count_int zs_htab[HSIZE];
|
||||
u_short zs_codetab[HSIZE];
|
||||
code_int zs_hsize; /* For dynamic table sizing. */
|
||||
code_int zs_free_ent; /* First unused entry. */
|
||||
/*
|
||||
|
|
@ -127,10 +122,8 @@ struct s_zstate {
|
|||
|
||||
static code_int getcode(struct s_zstate *zs);
|
||||
|
||||
static off_t
|
||||
zuncompress(FILE *in, FILE *out, char *pre, size_t prelen,
|
||||
off_t *compressed_bytes)
|
||||
{
|
||||
static off_t zuncompress(FILE *in, FILE *out, char *pre, size_t prelen,
|
||||
off_t *compressed_bytes) {
|
||||
off_t bin, bout = 0;
|
||||
char *buf;
|
||||
|
||||
|
|
@ -160,17 +153,13 @@ zuncompress(FILE *in, FILE *out, char *pre, size_t prelen,
|
|||
return bout;
|
||||
}
|
||||
|
||||
static int
|
||||
zclose(void *zs)
|
||||
{
|
||||
static int zclose(void *zs) {
|
||||
free(zs);
|
||||
/* We leave the caller to close the fd passed to zdopen() */
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *
|
||||
zdopen(int fd)
|
||||
{
|
||||
FILE *zdopen(int fd) {
|
||||
struct s_zstate *zs;
|
||||
|
||||
if ((zs = calloc(1, sizeof(struct s_zstate))) == NULL)
|
||||
|
|
@ -208,9 +197,7 @@ zdopen(int fd)
|
|||
* compressed file. The tables used herein are shared with those of the
|
||||
* compress() routine. See the definitions above.
|
||||
*/
|
||||
static int
|
||||
zread(void *cookie, char *rbp, int num)
|
||||
{
|
||||
static int zread(void *cookie, char *rbp, int num) {
|
||||
u_int count, i;
|
||||
struct s_zstate *zs;
|
||||
u_char *bp, header[3];
|
||||
|
|
@ -254,7 +241,7 @@ zread(void *cookie, char *rbp, int num)
|
|||
zs->zs_maxcode = MAXCODE(zs->zs_n_bits = INIT_BITS);
|
||||
for (zs->u.r.zs_code = 255; zs->u.r.zs_code >= 0; zs->u.r.zs_code--) {
|
||||
tab_prefixof(zs->u.r.zs_code) = 0;
|
||||
tab_suffixof(zs->u.r.zs_code) = (char_type) zs->u.r.zs_code;
|
||||
tab_suffixof(zs->u.r.zs_code) = (char_type)zs->u.r.zs_code;
|
||||
}
|
||||
zs->zs_free_ent = zs->zs_block_compress ? FIRST : 256;
|
||||
|
||||
|
|
@ -264,8 +251,7 @@ zread(void *cookie, char *rbp, int num)
|
|||
while ((zs->u.r.zs_code = getcode(zs)) > -1) {
|
||||
|
||||
if ((zs->u.r.zs_code == CLEAR) && zs->zs_block_compress) {
|
||||
for (zs->u.r.zs_code = 255; zs->u.r.zs_code >= 0;
|
||||
zs->u.r.zs_code--)
|
||||
for (zs->u.r.zs_code = 255; zs->u.r.zs_code >= 0; zs->u.r.zs_code--)
|
||||
tab_prefixof(zs->u.r.zs_code) = 0;
|
||||
zs->zs_clear_flg = 1;
|
||||
zs->zs_free_ent = FIRST;
|
||||
|
|
@ -276,8 +262,7 @@ zread(void *cookie, char *rbp, int num)
|
|||
|
||||
/* Special case for KwKwK string. */
|
||||
if (zs->u.r.zs_code >= zs->zs_free_ent) {
|
||||
if (zs->u.r.zs_code > zs->zs_free_ent ||
|
||||
zs->u.r.zs_oldcode == -1) {
|
||||
if (zs->u.r.zs_code > zs->zs_free_ent || zs->u.r.zs_oldcode == -1) {
|
||||
/* Bad stream. */
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
|
|
@ -300,7 +285,8 @@ zread(void *cookie, char *rbp, int num)
|
|||
*zs->u.r.zs_stackp++ = zs->u.r.zs_finchar = tab_suffixof(zs->u.r.zs_code);
|
||||
|
||||
/* And put them out in forward order. */
|
||||
middle: do {
|
||||
middle:
|
||||
do {
|
||||
if (count-- == 0)
|
||||
return (num);
|
||||
*bp++ = *--zs->u.r.zs_stackp;
|
||||
|
|
@ -309,7 +295,7 @@ middle: do {
|
|||
/* Generate the new entry. */
|
||||
if ((zs->u.r.zs_code = zs->zs_free_ent) < zs->zs_maxmaxcode &&
|
||||
zs->u.r.zs_oldcode != -1) {
|
||||
tab_prefixof(zs->u.r.zs_code) = (u_short) zs->u.r.zs_oldcode;
|
||||
tab_prefixof(zs->u.r.zs_code) = (u_short)zs->u.r.zs_oldcode;
|
||||
tab_suffixof(zs->u.r.zs_code) = zs->u.r.zs_finchar;
|
||||
zs->zs_free_ent = zs->u.r.zs_code + 1;
|
||||
}
|
||||
|
|
@ -318,7 +304,8 @@ middle: do {
|
|||
zs->u.r.zs_oldcode = zs->u.r.zs_incode;
|
||||
}
|
||||
zs->zs_state = S_EOF;
|
||||
eof: return (num - count);
|
||||
eof:
|
||||
return (num - count);
|
||||
}
|
||||
|
||||
/*-
|
||||
|
|
@ -328,9 +315,7 @@ eof: return (num - count);
|
|||
* Outputs:
|
||||
* code or -1 is returned.
|
||||
*/
|
||||
static code_int
|
||||
getcode(struct s_zstate *zs)
|
||||
{
|
||||
static code_int getcode(struct s_zstate *zs) {
|
||||
code_int gcode;
|
||||
int r_off, bits, i;
|
||||
char_type *bp;
|
||||
|
|
@ -355,9 +340,11 @@ getcode(struct s_zstate *zs)
|
|||
zs->zs_clear_flg = 0;
|
||||
}
|
||||
/* XXX */
|
||||
for (i = 0; i < zs->zs_n_bits && compressed_prelen; i++, compressed_prelen--)
|
||||
for (i = 0; i < zs->zs_n_bits && compressed_prelen;
|
||||
i++, compressed_prelen--)
|
||||
zs->u.r.zs_gbuf[i] = *compressed_pre++;
|
||||
zs->u.r.zs_size = fread(zs->u.r.zs_gbuf + i, 1, zs->zs_n_bits - i, zs->zs_fp);
|
||||
zs->u.r.zs_size =
|
||||
fread(zs->u.r.zs_gbuf + i, 1, zs->zs_n_bits - i, zs->zs_fp);
|
||||
zs->u.r.zs_size += i;
|
||||
if (zs->u.r.zs_size <= 0) /* End of file. */
|
||||
return (-1);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user