zlib 1.3.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4455 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
103
deps/zlib/test/example.c
vendored
103
deps/zlib/test/example.c
vendored
@ -34,37 +34,14 @@ static z_const char hello[] = "hello, hello!";
|
||||
static const char dictionary[] = "hello";
|
||||
static uLong dictId; /* Adler32 value of the dictionary */
|
||||
|
||||
void test_deflate OF((Byte *compr, uLong comprLen));
|
||||
void test_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_large_deflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_large_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_flush OF((Byte *compr, uLong *comprLen));
|
||||
void test_sync OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_dict_deflate OF((Byte *compr, uLong comprLen));
|
||||
void test_dict_inflate OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
int main OF((int argc, char *argv[]));
|
||||
|
||||
|
||||
#ifdef Z_SOLO
|
||||
|
||||
void *myalloc OF((void *, unsigned, unsigned));
|
||||
void myfree OF((void *, void *));
|
||||
|
||||
void *myalloc(q, n, m)
|
||||
void *q;
|
||||
unsigned n, m;
|
||||
{
|
||||
void *myalloc(void *q, unsigned n, unsigned m) {
|
||||
(void)q;
|
||||
return calloc(n, m);
|
||||
}
|
||||
|
||||
void myfree(void *q, void *p)
|
||||
{
|
||||
void myfree(void *q, void *p) {
|
||||
(void)q;
|
||||
free(p);
|
||||
}
|
||||
@ -77,18 +54,11 @@ static free_func zfree = myfree;
|
||||
static alloc_func zalloc = (alloc_func)0;
|
||||
static free_func zfree = (free_func)0;
|
||||
|
||||
void test_compress OF((Byte *compr, uLong comprLen,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
void test_gzio OF((const char *fname,
|
||||
Byte *uncompr, uLong uncomprLen));
|
||||
|
||||
/* ===========================================================================
|
||||
* Test compress() and uncompress()
|
||||
*/
|
||||
void test_compress(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_compress(Byte *compr, uLong comprLen, Byte *uncompr,
|
||||
uLong uncomprLen) {
|
||||
int err;
|
||||
uLong len = (uLong)strlen(hello)+1;
|
||||
|
||||
@ -111,11 +81,7 @@ void test_compress(compr, comprLen, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test read/write of .gz files
|
||||
*/
|
||||
void test_gzio(fname, uncompr, uncomprLen)
|
||||
const char *fname; /* compressed file name */
|
||||
Byte *uncompr;
|
||||
uLong uncomprLen;
|
||||
{
|
||||
void test_gzio(const char *fname, Byte *uncompr, uLong uncomprLen) {
|
||||
#ifdef NO_GZCOMPRESS
|
||||
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
|
||||
#else
|
||||
@ -197,10 +163,7 @@ void test_gzio(fname, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test deflate() with small buffers
|
||||
*/
|
||||
void test_deflate(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong comprLen;
|
||||
{
|
||||
void test_deflate(Byte *compr, uLong comprLen) {
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
uLong len = (uLong)strlen(hello)+1;
|
||||
@ -235,10 +198,8 @@ void test_deflate(compr, comprLen)
|
||||
/* ===========================================================================
|
||||
* Test inflate() with small buffers
|
||||
*/
|
||||
void test_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
|
||||
uLong uncomprLen) {
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
@ -276,10 +237,8 @@ void test_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test deflate() with large buffers and dynamic change of compression level
|
||||
*/
|
||||
void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_large_deflate(Byte *compr, uLong comprLen, Byte *uncompr,
|
||||
uLong uncomprLen) {
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
||||
@ -308,7 +267,7 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
||||
/* Feed in already compressed data and switch to no compression: */
|
||||
deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
|
||||
c_stream.next_in = compr;
|
||||
c_stream.avail_in = (uInt)comprLen/2;
|
||||
c_stream.avail_in = (uInt)uncomprLen/2;
|
||||
err = deflate(&c_stream, Z_NO_FLUSH);
|
||||
CHECK_ERR(err, "deflate");
|
||||
|
||||
@ -331,10 +290,8 @@ void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test inflate() with large buffers
|
||||
*/
|
||||
void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_large_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
|
||||
uLong uncomprLen) {
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
@ -361,7 +318,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
err = inflateEnd(&d_stream);
|
||||
CHECK_ERR(err, "inflateEnd");
|
||||
|
||||
if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
|
||||
if (d_stream.total_out != 2*uncomprLen + uncomprLen/2) {
|
||||
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
|
||||
exit(1);
|
||||
} else {
|
||||
@ -372,10 +329,7 @@ void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test deflate() with full flush
|
||||
*/
|
||||
void test_flush(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong *comprLen;
|
||||
{
|
||||
void test_flush(Byte *compr, uLong *comprLen) {
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
uInt len = (uInt)strlen(hello)+1;
|
||||
@ -410,10 +364,7 @@ void test_flush(compr, comprLen)
|
||||
/* ===========================================================================
|
||||
* Test inflateSync()
|
||||
*/
|
||||
void test_sync(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_sync(Byte *compr, uLong comprLen, Byte *uncompr, uLong uncomprLen) {
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
@ -453,10 +404,7 @@ void test_sync(compr, comprLen, uncompr, uncomprLen)
|
||||
/* ===========================================================================
|
||||
* Test deflate() with preset dictionary
|
||||
*/
|
||||
void test_dict_deflate(compr, comprLen)
|
||||
Byte *compr;
|
||||
uLong comprLen;
|
||||
{
|
||||
void test_dict_deflate(Byte *compr, uLong comprLen) {
|
||||
z_stream c_stream; /* compression stream */
|
||||
int err;
|
||||
|
||||
@ -490,10 +438,8 @@ void test_dict_deflate(compr, comprLen)
|
||||
/* ===========================================================================
|
||||
* Test inflate() with a preset dictionary
|
||||
*/
|
||||
void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen, uncomprLen;
|
||||
{
|
||||
void test_dict_inflate(Byte *compr, uLong comprLen, Byte *uncompr,
|
||||
uLong uncomprLen) {
|
||||
int err;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
@ -541,13 +487,10 @@ void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
|
||||
* Usage: example [output.gz [input.gz]]
|
||||
*/
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
Byte *compr, *uncompr;
|
||||
uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
|
||||
uLong uncomprLen = comprLen;
|
||||
uLong uncomprLen = 20000;
|
||||
uLong comprLen = 3 * uncomprLen;
|
||||
static const char* myVersion = ZLIB_VERSION;
|
||||
|
||||
if (zlibVersion()[0] != myVersion[0]) {
|
||||
@ -590,7 +533,7 @@ int main(argc, argv)
|
||||
|
||||
test_flush(compr, &comprLen);
|
||||
test_sync(compr, comprLen, uncompr, uncomprLen);
|
||||
comprLen = uncomprLen;
|
||||
comprLen = 3 * uncomprLen;
|
||||
|
||||
test_dict_deflate(compr, comprLen);
|
||||
test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
|
||||
|
5
deps/zlib/test/infcover.c
vendored
5
deps/zlib/test/infcover.c
vendored
@ -373,7 +373,7 @@ local void cover_support(void)
|
||||
mem_setup(&strm);
|
||||
strm.avail_in = 0;
|
||||
strm.next_in = Z_NULL;
|
||||
ret = inflateInit_(&strm, ZLIB_VERSION - 1, (int)sizeof(z_stream));
|
||||
ret = inflateInit_(&strm, "!", (int)sizeof(z_stream));
|
||||
assert(ret == Z_VERSION_ERROR);
|
||||
mem_done(&strm, "wrong version");
|
||||
|
||||
@ -462,7 +462,8 @@ local unsigned pull(void *desc, unsigned char **buf)
|
||||
|
||||
local int push(void *desc, unsigned char *buf, unsigned len)
|
||||
{
|
||||
buf += len;
|
||||
(void)buf;
|
||||
(void)len;
|
||||
return desc != Z_NULL; /* force error if desc not null */
|
||||
}
|
||||
|
||||
|
172
deps/zlib/test/minigzip.c
vendored
172
deps/zlib/test/minigzip.c
vendored
@ -59,7 +59,7 @@
|
||||
|
||||
#if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
|
||||
#ifndef WIN32 /* unlink already in stdio.h for WIN32 */
|
||||
extern int unlink OF((const char *));
|
||||
extern int unlink(const char *);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -149,20 +149,12 @@ static void pwinerror (s)
|
||||
# include <unistd.h> /* for unlink() */
|
||||
#endif
|
||||
|
||||
void *myalloc OF((void *, unsigned, unsigned));
|
||||
void myfree OF((void *, void *));
|
||||
|
||||
void *myalloc(q, n, m)
|
||||
void *q;
|
||||
unsigned n, m;
|
||||
{
|
||||
void *myalloc(void *q, unsigned n, unsigned m) {
|
||||
(void)q;
|
||||
return calloc(n, m);
|
||||
}
|
||||
|
||||
void myfree(q, p)
|
||||
void *q, *p;
|
||||
{
|
||||
void myfree(void *q, void *p) {
|
||||
(void)q;
|
||||
free(p);
|
||||
}
|
||||
@ -175,29 +167,7 @@ typedef struct gzFile_s {
|
||||
z_stream strm;
|
||||
} *gzFile;
|
||||
|
||||
gzFile gzopen OF((const char *, const char *));
|
||||
gzFile gzdopen OF((int, const char *));
|
||||
gzFile gz_open OF((const char *, int, const char *));
|
||||
|
||||
gzFile gzopen(path, mode)
|
||||
const char *path;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open(path, -1, mode);
|
||||
}
|
||||
|
||||
gzFile gzdopen(fd, mode)
|
||||
int fd;
|
||||
const char *mode;
|
||||
{
|
||||
return gz_open(NULL, fd, mode);
|
||||
}
|
||||
|
||||
gzFile gz_open(path, fd, mode)
|
||||
const char *path;
|
||||
int fd;
|
||||
const char *mode;
|
||||
{
|
||||
gzFile gz_open(const char *path, int fd, const char *mode) {
|
||||
gzFile gz;
|
||||
int ret;
|
||||
|
||||
@ -231,13 +201,15 @@ gzFile gz_open(path, fd, mode)
|
||||
return gz;
|
||||
}
|
||||
|
||||
int gzwrite OF((gzFile, const void *, unsigned));
|
||||
gzFile gzopen(const char *path, const char *mode) {
|
||||
return gz_open(path, -1, mode);
|
||||
}
|
||||
|
||||
int gzwrite(gz, buf, len)
|
||||
gzFile gz;
|
||||
const void *buf;
|
||||
unsigned len;
|
||||
{
|
||||
gzFile gzdopen(int fd, const char *mode) {
|
||||
return gz_open(NULL, fd, mode);
|
||||
}
|
||||
|
||||
int gzwrite(gzFile gz, const void *buf, unsigned len) {
|
||||
z_stream *strm;
|
||||
unsigned char out[BUFLEN];
|
||||
|
||||
@ -255,13 +227,7 @@ int gzwrite(gz, buf, len)
|
||||
return len;
|
||||
}
|
||||
|
||||
int gzread OF((gzFile, void *, unsigned));
|
||||
|
||||
int gzread(gz, buf, len)
|
||||
gzFile gz;
|
||||
void *buf;
|
||||
unsigned len;
|
||||
{
|
||||
int gzread(gzFile gz, void *buf, unsigned len) {
|
||||
int ret;
|
||||
unsigned got;
|
||||
unsigned char in[1];
|
||||
@ -292,11 +258,7 @@ int gzread(gz, buf, len)
|
||||
return len - strm->avail_out;
|
||||
}
|
||||
|
||||
int gzclose OF((gzFile));
|
||||
|
||||
int gzclose(gz)
|
||||
gzFile gz;
|
||||
{
|
||||
int gzclose(gzFile gz) {
|
||||
z_stream *strm;
|
||||
unsigned char out[BUFLEN];
|
||||
|
||||
@ -321,12 +283,7 @@ int gzclose(gz)
|
||||
return Z_OK;
|
||||
}
|
||||
|
||||
const char *gzerror OF((gzFile, int *));
|
||||
|
||||
const char *gzerror(gz, err)
|
||||
gzFile gz;
|
||||
int *err;
|
||||
{
|
||||
const char *gzerror(gzFile gz, int *err) {
|
||||
*err = gz->err;
|
||||
return gz->msg;
|
||||
}
|
||||
@ -335,67 +292,20 @@ const char *gzerror(gz, err)
|
||||
|
||||
static char *prog;
|
||||
|
||||
void error OF((const char *msg));
|
||||
void gz_compress OF((FILE *in, gzFile out));
|
||||
#ifdef USE_MMAP
|
||||
int gz_compress_mmap OF((FILE *in, gzFile out));
|
||||
#endif
|
||||
void gz_uncompress OF((gzFile in, FILE *out));
|
||||
void file_compress OF((char *file, char *mode));
|
||||
void file_uncompress OF((char *file));
|
||||
int main OF((int argc, char *argv[]));
|
||||
|
||||
/* ===========================================================================
|
||||
* Display error message and exit
|
||||
*/
|
||||
void error(msg)
|
||||
const char *msg;
|
||||
{
|
||||
void error(const char *msg) {
|
||||
fprintf(stderr, "%s: %s\n", prog, msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Compress input to output then close both files.
|
||||
*/
|
||||
|
||||
void gz_compress(in, out)
|
||||
FILE *in;
|
||||
gzFile out;
|
||||
{
|
||||
local char buf[BUFLEN];
|
||||
int len;
|
||||
int err;
|
||||
|
||||
#ifdef USE_MMAP
|
||||
/* Try first compressing with mmap. If mmap fails (minigzip used in a
|
||||
* pipe), use the normal fread loop.
|
||||
*/
|
||||
if (gz_compress_mmap(in, out) == Z_OK) return;
|
||||
#endif
|
||||
for (;;) {
|
||||
len = (int)fread(buf, 1, sizeof(buf), in);
|
||||
if (ferror(in)) {
|
||||
perror("fread");
|
||||
exit(1);
|
||||
}
|
||||
if (len == 0) break;
|
||||
|
||||
if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
|
||||
}
|
||||
fclose(in);
|
||||
if (gzclose(out) != Z_OK) error("failed gzclose");
|
||||
}
|
||||
|
||||
#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
|
||||
|
||||
/* Try compressing the input file at once using mmap. Return Z_OK if
|
||||
* if success, Z_ERRNO otherwise.
|
||||
*/
|
||||
int gz_compress_mmap(in, out)
|
||||
FILE *in;
|
||||
gzFile out;
|
||||
{
|
||||
int gz_compress_mmap(FILE *in, gzFile out) {
|
||||
int len;
|
||||
int err;
|
||||
int ifd = fileno(in);
|
||||
@ -424,13 +334,39 @@ int gz_compress_mmap(in, out)
|
||||
}
|
||||
#endif /* USE_MMAP */
|
||||
|
||||
/* ===========================================================================
|
||||
* Compress input to output then close both files.
|
||||
*/
|
||||
|
||||
void gz_compress(FILE *in, gzFile out) {
|
||||
local char buf[BUFLEN];
|
||||
int len;
|
||||
int err;
|
||||
|
||||
#ifdef USE_MMAP
|
||||
/* Try first compressing with mmap. If mmap fails (minigzip used in a
|
||||
* pipe), use the normal fread loop.
|
||||
*/
|
||||
if (gz_compress_mmap(in, out) == Z_OK) return;
|
||||
#endif
|
||||
for (;;) {
|
||||
len = (int)fread(buf, 1, sizeof(buf), in);
|
||||
if (ferror(in)) {
|
||||
perror("fread");
|
||||
exit(1);
|
||||
}
|
||||
if (len == 0) break;
|
||||
|
||||
if (gzwrite(out, buf, (unsigned)len) != len) error(gzerror(out, &err));
|
||||
}
|
||||
fclose(in);
|
||||
if (gzclose(out) != Z_OK) error("failed gzclose");
|
||||
}
|
||||
|
||||
/* ===========================================================================
|
||||
* Uncompress input to output then close both files.
|
||||
*/
|
||||
void gz_uncompress(in, out)
|
||||
gzFile in;
|
||||
FILE *out;
|
||||
{
|
||||
void gz_uncompress(gzFile in, FILE *out) {
|
||||
local char buf[BUFLEN];
|
||||
int len;
|
||||
int err;
|
||||
@ -454,10 +390,7 @@ void gz_uncompress(in, out)
|
||||
* Compress the given file: create a corresponding .gz file and remove the
|
||||
* original.
|
||||
*/
|
||||
void file_compress(file, mode)
|
||||
char *file;
|
||||
char *mode;
|
||||
{
|
||||
void file_compress(char *file, char *mode) {
|
||||
local char outfile[MAX_NAME_LEN];
|
||||
FILE *in;
|
||||
gzFile out;
|
||||
@ -493,9 +426,7 @@ void file_compress(file, mode)
|
||||
/* ===========================================================================
|
||||
* Uncompress the given file and remove the original.
|
||||
*/
|
||||
void file_uncompress(file)
|
||||
char *file;
|
||||
{
|
||||
void file_uncompress(char *file) {
|
||||
local char buf[MAX_NAME_LEN];
|
||||
char *infile, *outfile;
|
||||
FILE *out;
|
||||
@ -553,10 +484,7 @@ void file_uncompress(file)
|
||||
* -1 to -9 : compression level
|
||||
*/
|
||||
|
||||
int main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
int copyout = 0;
|
||||
int uncompr = 0;
|
||||
gzFile file;
|
||||
|
Reference in New Issue
Block a user