| 1 | /* minigzip.c -- simulate gzip using the zlib compression library
|
|---|
| 2 | * Copyright (C) 1995-2002 Jean-loup Gailly.
|
|---|
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | * minigzip is a minimal implementation of the gzip utility. This is
|
|---|
| 8 | * only an example of using zlib and isn't meant to replace the
|
|---|
| 9 | * full-featured gzip. No attempt is made to deal with file systems
|
|---|
| 10 | * limiting names to 14 or 8+3 characters, etc... Error checking is
|
|---|
| 11 | * very limited. So use minigzip only for testing; use gzip for the
|
|---|
| 12 | * real thing. On MSDOS, use only on file names without extension
|
|---|
| 13 | * or in pipe mode.
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | /* @(#) $Id: minigzip.c,v 1.1.1.2 2002/03/11 21:53:26 tromey Exp $ */
|
|---|
| 17 |
|
|---|
| 18 | #include <stdio.h>
|
|---|
| 19 | #include "zlib.h"
|
|---|
| 20 |
|
|---|
| 21 | #ifdef STDC
|
|---|
| 22 | # include <string.h>
|
|---|
| 23 | # include <stdlib.h>
|
|---|
| 24 | #else
|
|---|
| 25 | extern void exit OF((int));
|
|---|
| 26 | #endif
|
|---|
| 27 |
|
|---|
| 28 | #ifdef USE_MMAP
|
|---|
| 29 | # include <sys/types.h>
|
|---|
| 30 | # include <sys/mman.h>
|
|---|
| 31 | # include <sys/stat.h>
|
|---|
| 32 | #endif
|
|---|
| 33 |
|
|---|
| 34 | #if defined(MSDOS) || defined(OS2) || defined(WIN32)
|
|---|
| 35 | # include <fcntl.h>
|
|---|
| 36 | # include <io.h>
|
|---|
| 37 | # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
|
|---|
| 38 | #else
|
|---|
| 39 | # define SET_BINARY_MODE(file)
|
|---|
| 40 | #endif
|
|---|
| 41 |
|
|---|
| 42 | #ifdef VMS
|
|---|
| 43 | # define unlink delete
|
|---|
| 44 | # define GZ_SUFFIX "-gz"
|
|---|
| 45 | #endif
|
|---|
| 46 | #ifdef RISCOS
|
|---|
| 47 | # define unlink remove
|
|---|
| 48 | # define GZ_SUFFIX "-gz"
|
|---|
| 49 | # define fileno(file) file->__file
|
|---|
| 50 | #endif
|
|---|
| 51 | #if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
|
|---|
| 52 | # include <unix.h> /* for fileno */
|
|---|
| 53 | #endif
|
|---|
| 54 |
|
|---|
| 55 | #ifndef WIN32 /* unlink already in stdio.h for WIN32 */
|
|---|
| 56 | extern int unlink OF((const char *));
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | #ifndef GZ_SUFFIX
|
|---|
| 60 | # define GZ_SUFFIX ".gz"
|
|---|
| 61 | #endif
|
|---|
| 62 | #define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
|
|---|
| 63 |
|
|---|
| 64 | #define BUFLEN 16384
|
|---|
| 65 | #define MAX_NAME_LEN 1024
|
|---|
| 66 |
|
|---|
| 67 | #ifdef MAXSEG_64K
|
|---|
| 68 | # define local static
|
|---|
| 69 | /* Needed for systems with limitation on stack size. */
|
|---|
| 70 | #else
|
|---|
| 71 | # define local
|
|---|
| 72 | #endif
|
|---|
| 73 |
|
|---|
| 74 | char *prog;
|
|---|
| 75 |
|
|---|
| 76 | void error OF((const char *msg));
|
|---|
| 77 | void gz_compress OF((FILE *in, gzFile out));
|
|---|
| 78 | #ifdef USE_MMAP
|
|---|
| 79 | int gz_compress_mmap OF((FILE *in, gzFile out));
|
|---|
| 80 | #endif
|
|---|
| 81 | void gz_uncompress OF((gzFile in, FILE *out));
|
|---|
| 82 | void file_compress OF((char *file, char *mode));
|
|---|
| 83 | void file_uncompress OF((char *file));
|
|---|
| 84 | int main OF((int argc, char *argv[]));
|
|---|
| 85 |
|
|---|
| 86 | /* ===========================================================================
|
|---|
| 87 | * Display error message and exit
|
|---|
| 88 | */
|
|---|
| 89 | void error(msg)
|
|---|
| 90 | const char *msg;
|
|---|
| 91 | {
|
|---|
| 92 | fprintf(stderr, "%s: %s\n", prog, msg);
|
|---|
| 93 | exit(1);
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | /* ===========================================================================
|
|---|
| 97 | * Compress input to output then close both files.
|
|---|
| 98 | */
|
|---|
|
|---|