/*
* Copyright (c) 1998 Michael Smith.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
__FBSDID("$FreeBSD$");
#include "stand.h"
#include <string.h>
#include <zlib.h>
struct z_file
{
int zf_rawfd;
int zf_endseen;
};
"zip",
};
static int
{
int result;
int req;
result = 0;
/* If we need more */
if (req > 0) {
/* move old data to bottom of buffer */
/* read to fill buffer and update availibility data */
if (result >= 0)
}
return(result);
}
/*
* Adapted from get_byte/check_header in libz
*
* Returns 0 if the header is OK, nonzero if not.
*/
static int
{
return(-1);
++*curoffp;
}
/* gzip flag byte */
static int
{
int c;
zf->zf_dataoffset = 0;
/* Check the gzip magic header */
return(1);
}
}
return(1);
}
/* Discard time, xflags and OS code: */
/* len is garbage if EOF but the loop below will quit anyway */
}
}
}
}
/* if there's data left, we're in business */
return((c == -1) ? 1 : 0);
}
static int
{
char *zfname;
int rawfd;
char *cp;
int error;
/* Have to be in "just read it" mode */
return(EPERM);
/* If the name already ends in .gz or .bz2, ignore it */
return(ENOENT);
/* Try to open the compressed datafile */
if (rawfd == -1) {
/* add .gz sufix and try again */
return(ENOMEM);
if (rawfd == -1)
return(ENOENT);
}
printf("zf_open: stat failed\n");
return(ENOENT);
}
return(EISDIR); /* best guess */
}
/* Allocate a z_file structure, populate it */
return(ENOMEM);
/* Verify that the file is gzipped */
if (check_header(zf)) {
return(EFTYPE);
}
/* Initialise the inflation engine */
return(EIO);
}
/* Looks OK, we'll take it */
return(0);
}
static int
{
return(0);
}
static int
{
int error;
printf("zf_read: fill error\n");
return(EIO);
}
printf("zf_read: unexpected EOF\n");
return(EIO);
break;
}
break;
}
return(EIO);
}
}
return(0);
}
static int
{
return(-1);
zf->zf_endseen = 0;
return(0);
}
static off_t
{
switch (where) {
case SEEK_SET:
break;
case SEEK_CUR:
break;
case SEEK_END:
target = -1;
default:
return(-1);
}
/* rewind if required */
return(-1);
/* skip forwards if required */
if (errno)
return(-1);
}
/* This is where we are (be honest if we overshot) */
}
static int
{
/* stat as normal, but indicate that size is unknown */
return (result);
if (pos2 != -1) {
else
} else
}
return(result);
}