mirror of
https://github.com/GerbilSoft/zlib-ng.git
synced 2025-06-18 19:45:37 -04:00
Make internal functions static in the test code.
To avoid warnings when building with -Wmissing-prototypes. madler/zlib#bd9c329c1055a9265812352655ed2eec93f36e92
This commit is contained in:
parent
a4c236c4f0
commit
41ed14070b
@ -25,20 +25,6 @@ static unsigned long dictId = 0; /* Adler32 value of the dictionary */
|
|||||||
/* Maximum dictionary size, according to inflateGetDictionary() description. */
|
/* Maximum dictionary size, according to inflateGetDictionary() description. */
|
||||||
#define MAX_DICTIONARY_SIZE 32768
|
#define MAX_DICTIONARY_SIZE 32768
|
||||||
|
|
||||||
|
|
||||||
void test_compress (unsigned char *compr, z_uintmax_t comprLen, unsigned char *uncompr, z_uintmax_t uncomprLen);
|
|
||||||
void test_gzio (const char *fname, unsigned char *uncompr, z_size_t uncomprLen);
|
|
||||||
void test_deflate (unsigned char *compr, size_t comprLen);
|
|
||||||
void test_inflate (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen);
|
|
||||||
void test_large_deflate (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen, int zng_params);
|
|
||||||
void test_large_inflate (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen);
|
|
||||||
void test_flush (unsigned char *compr, z_uintmax_t *comprLen);
|
|
||||||
void test_sync (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen);
|
|
||||||
void test_dict_deflate (unsigned char *compr, size_t comprLen);
|
|
||||||
void test_dict_inflate (unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen);
|
|
||||||
int main (int argc, char *argv[]);
|
|
||||||
|
|
||||||
|
|
||||||
static alloc_func zalloc = NULL;
|
static alloc_func zalloc = NULL;
|
||||||
static free_func zfree = NULL;
|
static free_func zfree = NULL;
|
||||||
|
|
||||||
@ -63,7 +49,7 @@ void error(const char *format, ...) {
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test compress() and uncompress()
|
* Test compress() and uncompress()
|
||||||
*/
|
*/
|
||||||
void test_compress(unsigned char *compr, z_uintmax_t comprLen, unsigned char *uncompr, z_uintmax_t uncomprLen) {
|
static void test_compress(unsigned char *compr, z_uintmax_t comprLen, unsigned char *uncompr, z_uintmax_t uncomprLen) {
|
||||||
int err;
|
int err;
|
||||||
unsigned int len = (unsigned int)strlen(hello)+1;
|
unsigned int len = (unsigned int)strlen(hello)+1;
|
||||||
|
|
||||||
@ -84,7 +70,7 @@ void test_compress(unsigned char *compr, z_uintmax_t comprLen, unsigned char *un
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test read/write of .gz files
|
* Test read/write of .gz files
|
||||||
*/
|
*/
|
||||||
void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen) {
|
static void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen) {
|
||||||
#ifdef NO_GZCOMPRESS
|
#ifdef NO_GZCOMPRESS
|
||||||
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
|
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
|
||||||
#else
|
#else
|
||||||
@ -193,7 +179,7 @@ void test_gzio(const char *fname, unsigned char *uncompr, z_size_t uncomprLen) {
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test deflate() with small buffers
|
* Test deflate() with small buffers
|
||||||
*/
|
*/
|
||||||
void test_deflate(unsigned char *compr, size_t comprLen) {
|
static void test_deflate(unsigned char *compr, size_t comprLen) {
|
||||||
PREFIX3(stream) c_stream; /* compression stream */
|
PREFIX3(stream) c_stream; /* compression stream */
|
||||||
int err;
|
int err;
|
||||||
size_t len = strlen(hello)+1;
|
size_t len = strlen(hello)+1;
|
||||||
@ -230,7 +216,7 @@ void test_deflate(unsigned char *compr, size_t comprLen) {
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test inflate() with small buffers
|
* Test inflate() with small buffers
|
||||||
*/
|
*/
|
||||||
void test_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
|
static void test_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
|
||||||
int err;
|
int err;
|
||||||
PREFIX3(stream) d_stream; /* decompression stream */
|
PREFIX3(stream) d_stream; /* decompression stream */
|
||||||
|
|
||||||
@ -270,7 +256,7 @@ static unsigned int diff;
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test deflate() with large buffers and dynamic change of compression level
|
* Test deflate() with large buffers and dynamic change of compression level
|
||||||
*/
|
*/
|
||||||
void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen, int zng_params) {
|
static void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen, int zng_params) {
|
||||||
PREFIX3(stream) c_stream; /* compression stream */
|
PREFIX3(stream) c_stream; /* compression stream */
|
||||||
int err;
|
int err;
|
||||||
#ifndef ZLIB_COMPAT
|
#ifndef ZLIB_COMPAT
|
||||||
@ -364,7 +350,7 @@ void test_large_deflate(unsigned char *compr, size_t comprLen, unsigned char *un
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test inflate() with large buffers
|
* Test inflate() with large buffers
|
||||||
*/
|
*/
|
||||||
void test_large_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
|
static void test_large_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
|
||||||
int err;
|
int err;
|
||||||
PREFIX3(stream) d_stream; /* decompression stream */
|
PREFIX3(stream) d_stream; /* decompression stream */
|
||||||
|
|
||||||
@ -402,7 +388,7 @@ void test_large_inflate(unsigned char *compr, size_t comprLen, unsigned char *un
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test deflate() with full flush
|
* Test deflate() with full flush
|
||||||
*/
|
*/
|
||||||
void test_flush(unsigned char *compr, z_uintmax_t *comprLen) {
|
static void test_flush(unsigned char *compr, z_uintmax_t *comprLen) {
|
||||||
PREFIX3(stream) c_stream; /* compression stream */
|
PREFIX3(stream) c_stream; /* compression stream */
|
||||||
int err;
|
int err;
|
||||||
unsigned int len = (unsigned int)strlen(hello)+1;
|
unsigned int len = (unsigned int)strlen(hello)+1;
|
||||||
@ -439,7 +425,7 @@ void test_flush(unsigned char *compr, z_uintmax_t *comprLen) {
|
|||||||
* Test inflateSync()
|
* Test inflateSync()
|
||||||
* We expect a certain compressed block layout, so skip this with the original zlib.
|
* We expect a certain compressed block layout, so skip this with the original zlib.
|
||||||
*/
|
*/
|
||||||
void test_sync(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
|
static void test_sync(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
|
||||||
int err;
|
int err;
|
||||||
PREFIX3(stream) d_stream; /* decompression stream */
|
PREFIX3(stream) d_stream; /* decompression stream */
|
||||||
|
|
||||||
@ -478,7 +464,7 @@ void test_sync(unsigned char *compr, size_t comprLen, unsigned char *uncompr, si
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test deflate() with preset dictionary
|
* Test deflate() with preset dictionary
|
||||||
*/
|
*/
|
||||||
void test_dict_deflate(unsigned char *compr, size_t comprLen) {
|
static void test_dict_deflate(unsigned char *compr, size_t comprLen) {
|
||||||
PREFIX3(stream) c_stream; /* compression stream */
|
PREFIX3(stream) c_stream; /* compression stream */
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@ -511,7 +497,7 @@ void test_dict_deflate(unsigned char *compr, size_t comprLen) {
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test inflate() with a preset dictionary
|
* Test inflate() with a preset dictionary
|
||||||
*/
|
*/
|
||||||
void test_dict_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
|
static void test_dict_inflate(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
|
||||||
int err;
|
int err;
|
||||||
uint8_t check_dictionary[MAX_DICTIONARY_SIZE];
|
uint8_t check_dictionary[MAX_DICTIONARY_SIZE];
|
||||||
uint32_t check_dictionary_len = 0;
|
uint32_t check_dictionary_len = 0;
|
||||||
@ -570,7 +556,7 @@ void test_dict_inflate(unsigned char *compr, size_t comprLen, unsigned char *unc
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test deflateBound() with small buffers
|
* Test deflateBound() with small buffers
|
||||||
*/
|
*/
|
||||||
void test_deflate_bound(void) {
|
static void test_deflate_bound(void) {
|
||||||
PREFIX3(stream) c_stream; /* compression stream */
|
PREFIX3(stream) c_stream; /* compression stream */
|
||||||
int err;
|
int err;
|
||||||
unsigned int len = (unsigned int)strlen(hello)+1;
|
unsigned int len = (unsigned int)strlen(hello)+1;
|
||||||
@ -615,7 +601,7 @@ void test_deflate_bound(void) {
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test deflateCopy() with small buffers
|
* Test deflateCopy() with small buffers
|
||||||
*/
|
*/
|
||||||
void test_deflate_copy(unsigned char *compr, size_t comprLen) {
|
static void test_deflate_copy(unsigned char *compr, size_t comprLen) {
|
||||||
PREFIX3(stream) c_stream, c_stream_copy; /* compression stream */
|
PREFIX3(stream) c_stream, c_stream_copy; /* compression stream */
|
||||||
int err;
|
int err;
|
||||||
size_t len = strlen(hello)+1;
|
size_t len = strlen(hello)+1;
|
||||||
@ -663,7 +649,7 @@ void test_deflate_copy(unsigned char *compr, size_t comprLen) {
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test deflateGetDictionary() with small buffers
|
* Test deflateGetDictionary() with small buffers
|
||||||
*/
|
*/
|
||||||
void test_deflate_get_dict(unsigned char *compr, size_t comprLen) {
|
static void test_deflate_get_dict(unsigned char *compr, size_t comprLen) {
|
||||||
PREFIX3(stream) c_stream; /* compression stream */
|
PREFIX3(stream) c_stream; /* compression stream */
|
||||||
int err;
|
int err;
|
||||||
unsigned char *dictNew = NULL;
|
unsigned char *dictNew = NULL;
|
||||||
@ -706,7 +692,7 @@ void test_deflate_get_dict(unsigned char *compr, size_t comprLen) {
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test deflatePending() with small buffers
|
* Test deflatePending() with small buffers
|
||||||
*/
|
*/
|
||||||
void test_deflate_pending(unsigned char *compr, size_t comprLen) {
|
static void test_deflate_pending(unsigned char *compr, size_t comprLen) {
|
||||||
PREFIX3(stream) c_stream; /* compression stream */
|
PREFIX3(stream) c_stream; /* compression stream */
|
||||||
int err;
|
int err;
|
||||||
int *bits = calloc(256, 1);
|
int *bits = calloc(256, 1);
|
||||||
@ -757,7 +743,7 @@ void test_deflate_pending(unsigned char *compr, size_t comprLen) {
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test deflatePrime() wrapping gzip around deflate stream
|
* Test deflatePrime() wrapping gzip around deflate stream
|
||||||
*/
|
*/
|
||||||
void test_deflate_prime(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
|
static void test_deflate_prime(unsigned char *compr, size_t comprLen, unsigned char *uncompr, size_t uncomprLen) {
|
||||||
PREFIX3(stream) c_stream; /* compression stream */
|
PREFIX3(stream) c_stream; /* compression stream */
|
||||||
PREFIX3(stream) d_stream; /* decompression stream */
|
PREFIX3(stream) d_stream; /* decompression stream */
|
||||||
int err;
|
int err;
|
||||||
@ -846,7 +832,7 @@ void test_deflate_prime(unsigned char *compr, size_t comprLen, unsigned char *un
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test deflateSetHeader() with small buffers
|
* Test deflateSetHeader() with small buffers
|
||||||
*/
|
*/
|
||||||
void test_deflate_set_header(unsigned char *compr, size_t comprLen) {
|
static void test_deflate_set_header(unsigned char *compr, size_t comprLen) {
|
||||||
PREFIX(gz_header) *head = calloc(1, sizeof(PREFIX(gz_header)));
|
PREFIX(gz_header) *head = calloc(1, sizeof(PREFIX(gz_header)));
|
||||||
PREFIX3(stream) c_stream; /* compression stream */
|
PREFIX3(stream) c_stream; /* compression stream */
|
||||||
int err;
|
int err;
|
||||||
@ -904,7 +890,7 @@ void test_deflate_set_header(unsigned char *compr, size_t comprLen) {
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Test deflateTune() with small buffers
|
* Test deflateTune() with small buffers
|
||||||
*/
|
*/
|
||||||
void test_deflate_tune(unsigned char *compr, size_t comprLen) {
|
static void test_deflate_tune(unsigned char *compr, size_t comprLen) {
|
||||||
PREFIX3(stream) c_stream; /* compression stream */
|
PREFIX3(stream) c_stream; /* compression stream */
|
||||||
int err;
|
int err;
|
||||||
int good_length = 3;
|
int good_length = 3;
|
||||||
|
@ -56,62 +56,20 @@ extern int unlink (const char *);
|
|||||||
|
|
||||||
static const char *prog = "minigzip_fuzzer";
|
static const char *prog = "minigzip_fuzzer";
|
||||||
|
|
||||||
void error (const char *msg);
|
|
||||||
void gz_compress (FILE *in, gzFile out);
|
|
||||||
#ifdef USE_MMAP
|
|
||||||
int gz_compress_mmap (FILE *in, gzFile out);
|
|
||||||
#endif
|
|
||||||
void gz_uncompress (gzFile in, FILE *out);
|
|
||||||
void file_compress (char *file, char *mode);
|
|
||||||
void file_uncompress (char *file);
|
|
||||||
int main (int argc, char *argv[]);
|
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Display error message and exit
|
* Display error message and exit
|
||||||
*/
|
*/
|
||||||
void error(const char *msg) {
|
static void error(const char *msg) {
|
||||||
fprintf(stderr, "%s: %s\n", prog, msg);
|
fprintf(stderr, "%s: %s\n", prog, msg);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
|
||||||
* Compress input to output then close both files.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void gz_compress(FILE *in, gzFile out) {
|
|
||||||
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
|
|
||||||
/* Clear out the contents of buf before reading from the file to avoid
|
|
||||||
MemorySanitizer: use-of-uninitialized-value warnings. */
|
|
||||||
memset(buf, 0, sizeof(buf));
|
|
||||||
for (;;) {
|
|
||||||
len = (int)fread(buf, 1, sizeof(buf), in);
|
|
||||||
if (ferror(in)) {
|
|
||||||
perror("fread");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
if (len == 0) break;
|
|
||||||
|
|
||||||
if (PREFIX(gzwrite)(out, buf, (unsigned)len) != len) error(PREFIX(gzerror)(out, &err));
|
|
||||||
}
|
|
||||||
fclose(in);
|
|
||||||
if (PREFIX(gzclose)(out) != Z_OK) error("failed gzclose");
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
|
#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
|
||||||
|
/* ===========================================================================
|
||||||
/* Try compressing the input file at once using mmap. Return Z_OK if
|
* Try compressing the input file at once using mmap. Return Z_OK if
|
||||||
* success, Z_ERRNO otherwise.
|
* success, Z_ERRNO otherwise.
|
||||||
*/
|
*/
|
||||||
int gz_compress_mmap(FILE *in, gzFile out) {
|
static int gz_compress_mmap(FILE *in, gzFile out) {
|
||||||
int len;
|
int len;
|
||||||
int err;
|
int err;
|
||||||
int ifd = fileno(in);
|
int ifd = fileno(in);
|
||||||
@ -140,10 +98,42 @@ int gz_compress_mmap(FILE *in, gzFile out) {
|
|||||||
}
|
}
|
||||||
#endif /* USE_MMAP */
|
#endif /* USE_MMAP */
|
||||||
|
|
||||||
|
/* ===========================================================================
|
||||||
|
* Compress input to output then close both files.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void gz_compress(FILE *in, gzFile out) {
|
||||||
|
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
|
||||||
|
/* Clear out the contents of buf before reading from the file to avoid
|
||||||
|
MemorySanitizer: use-of-uninitialized-value warnings. */
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
for (;;) {
|
||||||
|
len = (int)fread(buf, 1, sizeof(buf), in);
|
||||||
|
if (ferror(in)) {
|
||||||
|
perror("fread");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (len == 0) break;
|
||||||
|
|
||||||
|
if (PREFIX(gzwrite)(out, buf, (unsigned)len) != len) error(PREFIX(gzerror)(out, &err));
|
||||||
|
}
|
||||||
|
fclose(in);
|
||||||
|
if (PREFIX(gzclose)(out) != Z_OK) error("failed gzclose");
|
||||||
|
}
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Uncompress input to output then close both files.
|
* Uncompress input to output then close both files.
|
||||||
*/
|
*/
|
||||||
void gz_uncompress(gzFile in, FILE *out) {
|
static void gz_uncompress(gzFile in, FILE *out) {
|
||||||
char buf[BUFLENW];
|
char buf[BUFLENW];
|
||||||
int len;
|
int len;
|
||||||
int err;
|
int err;
|
||||||
@ -167,7 +157,7 @@ void gz_uncompress(gzFile in, FILE *out) {
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
void file_compress(char *file, char *mode) {
|
static void file_compress(char *file, char *mode) {
|
||||||
char outfile[MAX_NAME_LEN];
|
char outfile[MAX_NAME_LEN];
|
||||||
FILE *in;
|
FILE *in;
|
||||||
gzFile out;
|
gzFile out;
|
||||||
@ -194,11 +184,10 @@ void file_compress(char *file, char *mode) {
|
|||||||
unlink(file);
|
unlink(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Uncompress the given file and remove the original.
|
* Uncompress the given file and remove the original.
|
||||||
*/
|
*/
|
||||||
void file_uncompress(char *file) {
|
static void file_uncompress(char *file) {
|
||||||
char buf[MAX_NAME_LEN];
|
char buf[MAX_NAME_LEN];
|
||||||
char *infile, *outfile;
|
char *infile, *outfile;
|
||||||
FILE *out;
|
FILE *out;
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* deflate() using specialized parameters
|
* deflate() using specialized parameters
|
||||||
*/
|
*/
|
||||||
void deflate_params(FILE *fin, FILE *fout, int32_t read_buf_size, int32_t write_buf_size, int32_t level,
|
static void deflate_params(FILE *fin, FILE *fout, int32_t read_buf_size, int32_t write_buf_size, int32_t level,
|
||||||
int32_t window_bits, int32_t mem_level, int32_t strategy, int32_t flush) {
|
int32_t window_bits, int32_t mem_level, int32_t strategy, int32_t flush) {
|
||||||
PREFIX3(stream) c_stream; /* compression stream */
|
PREFIX3(stream) c_stream; /* compression stream */
|
||||||
uint8_t *read_buf;
|
uint8_t *read_buf;
|
||||||
@ -123,7 +123,7 @@ void deflate_params(FILE *fin, FILE *fout, int32_t read_buf_size, int32_t write_
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* inflate() using specialized parameters
|
* inflate() using specialized parameters
|
||||||
*/
|
*/
|
||||||
void inflate_params(FILE *fin, FILE *fout, int32_t read_buf_size, int32_t write_buf_size, int32_t window_bits,
|
static void inflate_params(FILE *fin, FILE *fout, int32_t read_buf_size, int32_t write_buf_size, int32_t window_bits,
|
||||||
int32_t flush) {
|
int32_t flush) {
|
||||||
PREFIX3(stream) d_stream; /* decompression stream */
|
PREFIX3(stream) d_stream; /* decompression stream */
|
||||||
uint8_t *read_buf;
|
uint8_t *read_buf;
|
||||||
@ -212,7 +212,7 @@ void inflate_params(FILE *fin, FILE *fout, int32_t read_buf_size, int32_t write_
|
|||||||
free(write_buf);
|
free(write_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void show_help(void) {
|
static void show_help(void) {
|
||||||
printf("Usage: minideflate [-c][-d][-k] [-f|-h|-R|-F] [-m level] [-r/-t size] [-s flush] [-w bits] [-0 to -9] [input file]\n\n"
|
printf("Usage: minideflate [-c][-d][-k] [-f|-h|-R|-F] [-m level] [-r/-t size] [-s flush] [-w bits] [-0 to -9] [input file]\n\n"
|
||||||
" -c : write to standard output\n"
|
" -c : write to standard output\n"
|
||||||
" -d : decompress\n"
|
" -d : decompress\n"
|
||||||
|
@ -60,21 +60,10 @@ extern int unlink (const char *);
|
|||||||
|
|
||||||
static char *prog;
|
static char *prog;
|
||||||
|
|
||||||
void error (const char *msg);
|
|
||||||
void gz_fatal (gzFile file);
|
|
||||||
void gz_compress (FILE *in, gzFile out);
|
|
||||||
#ifdef USE_MMAP
|
|
||||||
int gz_compress_mmap (FILE *in, gzFile out);
|
|
||||||
#endif
|
|
||||||
void gz_uncompress (gzFile in, FILE *out);
|
|
||||||
void file_compress (char *file, char *mode, int keep);
|
|
||||||
void file_uncompress (char *file, int keep);
|
|
||||||
int main (int argc, char *argv[]);
|
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Display error message and exit
|
* Display error message and exit
|
||||||
*/
|
*/
|
||||||
void error(const char *msg) {
|
static void error(const char *msg) {
|
||||||
fprintf(stderr, "%s: %s\n", prog, msg);
|
fprintf(stderr, "%s: %s\n", prog, msg);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -83,18 +72,51 @@ void error(const char *msg) {
|
|||||||
* Display last error message of gzFile, close it and exit
|
* Display last error message of gzFile, close it and exit
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void gz_fatal(gzFile file) {
|
static void gz_fatal(gzFile file) {
|
||||||
int err;
|
int err;
|
||||||
fprintf(stderr, "%s: %s\n", prog, PREFIX(gzerror)(file, &err));
|
fprintf(stderr, "%s: %s\n", prog, PREFIX(gzerror)(file, &err));
|
||||||
PREFIX(gzclose)(file);
|
PREFIX(gzclose)(file);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_MMAP /* MMAP version, Miguel Albrecht <malbrech@eso.org> */
|
||||||
|
/* ===========================================================================
|
||||||
|
* Try compressing the input file at once using mmap. Return Z_OK if
|
||||||
|
* success, Z_ERRNO otherwise.
|
||||||
|
*/
|
||||||
|
static int gz_compress_mmap(FILE *in, gzFile out) {
|
||||||
|
int len;
|
||||||
|
int ifd = fileno(in);
|
||||||
|
char *buf; /* mmap'ed buffer for the entire input file */
|
||||||
|
off_t buf_len; /* length of the input file */
|
||||||
|
struct stat sb;
|
||||||
|
|
||||||
|
/* Determine the size of the file, needed for mmap: */
|
||||||
|
if (fstat(ifd, &sb) < 0) return Z_ERRNO;
|
||||||
|
buf_len = sb.st_size;
|
||||||
|
if (buf_len <= 0) return Z_ERRNO;
|
||||||
|
|
||||||
|
/* Now do the actual mmap: */
|
||||||
|
buf = mmap((void *)0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
|
||||||
|
if (buf == (char *)(-1)) return Z_ERRNO;
|
||||||
|
|
||||||
|
/* Compress the whole file at once: */
|
||||||
|
len = PREFIX(gzwrite)(out, buf, (unsigned)buf_len);
|
||||||
|
|
||||||
|
if (len != (int)buf_len) gz_fatal(out);
|
||||||
|
|
||||||
|
munmap(buf, buf_len);
|
||||||
|
fclose(in);
|
||||||
|
if (PREFIX(gzclose)(out) != Z_OK) error("failed gzclose");
|
||||||
|
return Z_OK;
|
||||||
|
}
|
||||||
|
#endif /* USE_MMAP */
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Compress input to output then close both files.
|
* Compress input to output then close both files.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void gz_compress(FILE *in, gzFile out) {
|
static void gz_compress(FILE *in, gzFile out) {
|
||||||
char *buf;
|
char *buf;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
@ -126,43 +148,10 @@ void gz_compress(FILE *in, gzFile out) {
|
|||||||
if (PREFIX(gzclose)(out) != Z_OK) error("failed gzclose");
|
if (PREFIX(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
|
|
||||||
* success, Z_ERRNO otherwise.
|
|
||||||
*/
|
|
||||||
int gz_compress_mmap(FILE *in, gzFile out) {
|
|
||||||
int len;
|
|
||||||
int ifd = fileno(in);
|
|
||||||
char *buf; /* mmap'ed buffer for the entire input file */
|
|
||||||
off_t buf_len; /* length of the input file */
|
|
||||||
struct stat sb;
|
|
||||||
|
|
||||||
/* Determine the size of the file, needed for mmap: */
|
|
||||||
if (fstat(ifd, &sb) < 0) return Z_ERRNO;
|
|
||||||
buf_len = sb.st_size;
|
|
||||||
if (buf_len <= 0) return Z_ERRNO;
|
|
||||||
|
|
||||||
/* Now do the actual mmap: */
|
|
||||||
buf = mmap((void *)0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
|
|
||||||
if (buf == (char *)(-1)) return Z_ERRNO;
|
|
||||||
|
|
||||||
/* Compress the whole file at once: */
|
|
||||||
len = PREFIX(gzwrite)(out, buf, (unsigned)buf_len);
|
|
||||||
|
|
||||||
if (len != (int)buf_len) gz_fatal(out);
|
|
||||||
|
|
||||||
munmap(buf, buf_len);
|
|
||||||
fclose(in);
|
|
||||||
if (PREFIX(gzclose)(out) != Z_OK) error("failed gzclose");
|
|
||||||
return Z_OK;
|
|
||||||
}
|
|
||||||
#endif /* USE_MMAP */
|
|
||||||
|
|
||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Uncompress input to output then close both files.
|
* Uncompress input to output then close both files.
|
||||||
*/
|
*/
|
||||||
void gz_uncompress(gzFile in, FILE *out) {
|
static void gz_uncompress(gzFile in, FILE *out) {
|
||||||
char *buf = (char *)malloc(BUFLENW);
|
char *buf = (char *)malloc(BUFLENW);
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
@ -192,7 +181,7 @@ void gz_uncompress(gzFile in, FILE *out) {
|
|||||||
* 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.
|
||||||
*/
|
*/
|
||||||
void file_compress(char *file, char *mode, int keep) {
|
static void file_compress(char *file, char *mode, int keep) {
|
||||||
char outfile[MAX_NAME_LEN];
|
char outfile[MAX_NAME_LEN];
|
||||||
FILE *in;
|
FILE *in;
|
||||||
gzFile out;
|
gzFile out;
|
||||||
@ -224,7 +213,7 @@ void file_compress(char *file, char *mode, int keep) {
|
|||||||
/* ===========================================================================
|
/* ===========================================================================
|
||||||
* Uncompress the given file and remove the original.
|
* Uncompress the given file and remove the original.
|
||||||
*/
|
*/
|
||||||
void file_uncompress(char *file, int keep) {
|
static void file_uncompress(char *file, int keep) {
|
||||||
char buf[MAX_NAME_LEN];
|
char buf[MAX_NAME_LEN];
|
||||||
char *infile, *outfile;
|
char *infile, *outfile;
|
||||||
FILE *out;
|
FILE *out;
|
||||||
@ -264,7 +253,7 @@ void file_uncompress(char *file, int keep) {
|
|||||||
unlink(infile);
|
unlink(infile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void show_help(void) {
|
static void show_help(void) {
|
||||||
printf("Usage: minigzip [-c] [-d] [-k] [-f|-h|-R|-F|-T] [-A] [-0 to -9] [files...]\n\n"
|
printf("Usage: minigzip [-c] [-d] [-k] [-f|-h|-R|-F|-T] [-A] [-0 to -9] [files...]\n\n"
|
||||||
" -c : write to standard output\n"
|
" -c : write to standard output\n"
|
||||||
" -d : decompress\n"
|
" -d : decompress\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user