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