/*
* Copyright (c) 1998 Michael Smith.
* Copyright (c) 2000 Maxim Sobolev
* 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$");
#ifndef REGRESSION
#include "stand.h"
#else
#include <stdlib.h>
struct open_file {
};
#endif
#include <string.h>
#include <bzlib.h>
struct bz_file
{
int bzf_rawfd;
int bzf_endseen;
};
#ifndef REGRESSION
"bzip",
};
#endif
static int
{
int result;
int req;
result = 0;
/* If we need more */
if (req > 0) {
/* move old data to bottom of buffer */
if (req < BZ_BUFSIZE)
/* 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);
}
static int
{
unsigned int len;
int c;
/* Check the bzip2 magic header */
return(1);
}
}
/* Check that the block size is valid */
if (c < '1' || c > '9')
return(1);
/* Put back bytes that we've took from the input stream */
return(0);
}
static int
{
static char *bzfname;
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);
/* Construct new name */
return(ENOMEM);
/* Try to open the compressed datafile */
if (rawfd == -1)
return(ENOENT);
printf("bzf_open: stat failed\n");
return(ENOENT);
}
printf("bzf_open: not a file\n");
return(EISDIR); /* best guess */
}
/* Allocate a bz_file structure, populate it */
return(ENOMEM);
/* Verify that the file is bzipped */
if (check_header(bzf)) {
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("bzf_read: fill error\n");
return(EIO);
}
printf("bzf_read: unexpected EOF\n");
return(EIO);
break;
}
break;
}
return(EIO);
}
}
return(0);
}
static int
{
/*
* Since bzip2 does not have an equivalent inflateReset function a crude
* one needs to be provided. The functions all called in such a way that
* at any time an error occurs a roll back can be done (effectively making
* this rewind 'atomic', either the reset occurs successfully or not at all,
* with no 'undefined' state happening).
*/
/* Allocate a bz_file structure, populate it */
return(-1);
/* Initialise the inflation engine */
return(-1);
}
/* Seek back to the beginning of the file */
return(-1);
}
/* Free old bz_file data */
/* Use the new bz_file data */
return(0);
}
static off_t
{
switch (where) {
case SEEK_SET:
break;
case SEEK_CUR:
break;
case SEEK_END:
target = -1;
default:
return(-1);
}
/* Can we get there from here? */
return -1;
}
/* if bzf_rewind was called then bzf has changed */
/* skip forwards if required */
if (errno)
return(-1);
}
/* This is where we are (be honest if we overshot) */
}
static int
{
int result;
/* stat as normal, but indicate that size is unknown */
return(result);
}
void
{
}
#ifdef REGRESSION
/* Small test case, open and decompress test.bz2 */
int main()
{
struct open_file f;
int err;
memset(&f, '\0', sizeof(f));
if (err != 0)
exit(1);
do {
if (err != 0)
exit(2);
exit(0);
}
#endif