Basic gzip/gunzip in memory buffer examples using zlib code.

Dependencies:   mbed-rtos mbed

There are small changes needed to the zconf.h file in the zlib distribution (I used 1.2.7). The zlib license applies to the zlib code - I have only imported a subset of the source.

The MBED has limited memory, so we need the following (near the top of zconf.h) to restrict memory allocation sizes:

#define    MAX_MEM_LEVEL    3
#define    MAX_WBITS        10

Because MAX_MEM_LEVEL and MAX_WBITS are so much lower than the default, there is a danger that the mbed cannot gunzip data compressed by a 'normal' zlib build. My use-case is to gzip on the mbed more than gunzip on the mbed so I have not given much time to this issue.

I also included this (also near the top of zconf.h) to prefix defines with Z_

#define    Z_PREFIX

In zconf.h, in the zlib distribution, the includes for <fcntl.h> and <sys/types.h> need commenting out when using the online compiler. No need when using GCC4MBED.

I also looked at miniz. I chose zlib because I needed the gzip headers and miniz does not implement them.

The sample main.cpp reads source data, compresses it, decompresses it, and finally compares the input data with the output data to confirm they are the same.

    unsigned char input_data[2048];
    unsigned long input_data_length = 0;
    FILE *ifp = fopen("/local/src.txt", "r");
    if (ifp) {
        int br = fread(input_data, 1, sizeof(input_data), ifp);
        fclose(ifp);
        input_data_length = br;
    }
    printf("%s:%d: input_data_length:%lu%s", __FILE__, __LINE__, input_data_length, newline);
 
 
    unsigned char gzip_data[2048];
    unsigned long gzip_data_length = 0;
    if (input_data_length > 0) {
        gzip_data_length = sizeof(gzip_data);
        int rv = gzip(gzip_data, &gzip_data_length, input_data, input_data_length);
        if (Z_OK == rv) {
            FILE *ofp = fopen("/local/dst.gz", "w");
            if (ofp) {
                int bw = fwrite(gzip_data, 1, gzip_data_length, ofp);
                fclose(ofp);
            }
        } else {
            printf("%s:%d: %d%s", __FILE__, __LINE__, rv, newline);
        }
    }
    printf("%s:%d: gzip_data_length:%lu%s", __FILE__, __LINE__, gzip_data_length, newline);
 
 
    unsigned char output_data[2048];
    unsigned long output_data_length = 0;
    if (gzip_data_length > 0) {
        output_data_length = sizeof(output_data);
        int rv = gunzip(output_data, &output_data_length, gzip_data, gzip_data_length);
        if (Z_OK != rv) {
            printf("%s:%d: %d%s", __FILE__, __LINE__, rv, newline);
        }
    }
    printf("%s:%d: output_data_length:%lu%s", __FILE__, __LINE__, output_data_length, newline);
 
 
    if (input_data_length > 0 and input_data_length > 0) {
        bool input_matches_output = false;
        if (input_data_length == output_data_length) {
            input_matches_output = true;
            for ( size_t i = 0 ; input_matches_output && i < input_data_length ; i++ ) {
                if (input_data[i] != output_data[i]) {
                    input_matches_output = false;
                }
            }
        }
        printf("%s:%d: input (%lu bytes) %s output (%lu bytes)%s", __FILE__, __LINE__, input_data_length, input_matches_output?"matches":"does not match", output_data_length, newline);
    } else {
        printf("%s:%d: input and/or output length is 0%s", __FILE__, __LINE__, newline);
    }
Committer:
jonathonfletcher
Date:
Sun Oct 21 07:46:41 2012 +0000
Revision:
0:54f5be781526
initial checkin

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jonathonfletcher 0:54f5be781526 1 /* zconf.h -- configuration of the zlib compression library
jonathonfletcher 0:54f5be781526 2 * Copyright (C) 1995-2012 Jean-loup Gailly.
jonathonfletcher 0:54f5be781526 3 * For conditions of distribution and use, see copyright notice in zlib.h
jonathonfletcher 0:54f5be781526 4 */
jonathonfletcher 0:54f5be781526 5
jonathonfletcher 0:54f5be781526 6 /* @(#) $Id$ */
jonathonfletcher 0:54f5be781526 7
jonathonfletcher 0:54f5be781526 8 #ifndef ZCONF_H
jonathonfletcher 0:54f5be781526 9 #define ZCONF_H
jonathonfletcher 0:54f5be781526 10
jonathonfletcher 0:54f5be781526 11 #define Z_PREFIX
jonathonfletcher 0:54f5be781526 12 #define MAX_MEM_LEVEL 3
jonathonfletcher 0:54f5be781526 13 #define MAX_WBITS 10
jonathonfletcher 0:54f5be781526 14
jonathonfletcher 0:54f5be781526 15 /*
jonathonfletcher 0:54f5be781526 16 * If you *really* need a unique prefix for all types and library functions,
jonathonfletcher 0:54f5be781526 17 * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
jonathonfletcher 0:54f5be781526 18 * Even better than compiling with -DZ_PREFIX would be to use configure to set
jonathonfletcher 0:54f5be781526 19 * this permanently in zconf.h using "./configure --zprefix".
jonathonfletcher 0:54f5be781526 20 */
jonathonfletcher 0:54f5be781526 21 #ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
jonathonfletcher 0:54f5be781526 22 # define Z_PREFIX_SET
jonathonfletcher 0:54f5be781526 23
jonathonfletcher 0:54f5be781526 24 /* all linked symbols */
jonathonfletcher 0:54f5be781526 25 # define _dist_code z__dist_code
jonathonfletcher 0:54f5be781526 26 # define _length_code z__length_code
jonathonfletcher 0:54f5be781526 27 # define _tr_align z__tr_align
jonathonfletcher 0:54f5be781526 28 # define _tr_flush_block z__tr_flush_block
jonathonfletcher 0:54f5be781526 29 # define _tr_init z__tr_init
jonathonfletcher 0:54f5be781526 30 # define _tr_stored_block z__tr_stored_block
jonathonfletcher 0:54f5be781526 31 # define _tr_tally z__tr_tally
jonathonfletcher 0:54f5be781526 32 # define adler32 z_adler32
jonathonfletcher 0:54f5be781526 33 # define adler32_combine z_adler32_combine
jonathonfletcher 0:54f5be781526 34 # define adler32_combine64 z_adler32_combine64
jonathonfletcher 0:54f5be781526 35 # ifndef Z_SOLO
jonathonfletcher 0:54f5be781526 36 # define compress z_compress
jonathonfletcher 0:54f5be781526 37 # define compress2 z_compress2
jonathonfletcher 0:54f5be781526 38 # define compressBound z_compressBound
jonathonfletcher 0:54f5be781526 39 # endif
jonathonfletcher 0:54f5be781526 40 # define crc32 z_crc32
jonathonfletcher 0:54f5be781526 41 # define crc32_combine z_crc32_combine
jonathonfletcher 0:54f5be781526 42 # define crc32_combine64 z_crc32_combine64
jonathonfletcher 0:54f5be781526 43 # define deflate z_deflate
jonathonfletcher 0:54f5be781526 44 # define deflateBound z_deflateBound
jonathonfletcher 0:54f5be781526 45 # define deflateCopy z_deflateCopy
jonathonfletcher 0:54f5be781526 46 # define deflateEnd z_deflateEnd
jonathonfletcher 0:54f5be781526 47 # define deflateInit2_ z_deflateInit2_
jonathonfletcher 0:54f5be781526 48 # define deflateInit_ z_deflateInit_
jonathonfletcher 0:54f5be781526 49 # define deflateParams z_deflateParams
jonathonfletcher 0:54f5be781526 50 # define deflatePending z_deflatePending
jonathonfletcher 0:54f5be781526 51 # define deflatePrime z_deflatePrime
jonathonfletcher 0:54f5be781526 52 # define deflateReset z_deflateReset
jonathonfletcher 0:54f5be781526 53 # define deflateResetKeep z_deflateResetKeep
jonathonfletcher 0:54f5be781526 54 # define deflateSetDictionary z_deflateSetDictionary
jonathonfletcher 0:54f5be781526 55 # define deflateSetHeader z_deflateSetHeader
jonathonfletcher 0:54f5be781526 56 # define deflateTune z_deflateTune
jonathonfletcher 0:54f5be781526 57 # define deflate_copyright z_deflate_copyright
jonathonfletcher 0:54f5be781526 58 # define get_crc_table z_get_crc_table
jonathonfletcher 0:54f5be781526 59 # ifndef Z_SOLO
jonathonfletcher 0:54f5be781526 60 # define gz_error z_gz_error
jonathonfletcher 0:54f5be781526 61 # define gz_intmax z_gz_intmax
jonathonfletcher 0:54f5be781526 62 # define gz_strwinerror z_gz_strwinerror
jonathonfletcher 0:54f5be781526 63 # define gzbuffer z_gzbuffer
jonathonfletcher 0:54f5be781526 64 # define gzclearerr z_gzclearerr
jonathonfletcher 0:54f5be781526 65 # define gzclose z_gzclose
jonathonfletcher 0:54f5be781526 66 # define gzclose_r z_gzclose_r
jonathonfletcher 0:54f5be781526 67 # define gzclose_w z_gzclose_w
jonathonfletcher 0:54f5be781526 68 # define gzdirect z_gzdirect
jonathonfletcher 0:54f5be781526 69 # define gzdopen z_gzdopen
jonathonfletcher 0:54f5be781526 70 # define gzeof z_gzeof
jonathonfletcher 0:54f5be781526 71 # define gzerror z_gzerror
jonathonfletcher 0:54f5be781526 72 # define gzflush z_gzflush
jonathonfletcher 0:54f5be781526 73 # define gzgetc z_gzgetc
jonathonfletcher 0:54f5be781526 74 # define gzgetc_ z_gzgetc_
jonathonfletcher 0:54f5be781526 75 # define gzgets z_gzgets
jonathonfletcher 0:54f5be781526 76 # define gzoffset z_gzoffset
jonathonfletcher 0:54f5be781526 77 # define gzoffset64 z_gzoffset64
jonathonfletcher 0:54f5be781526 78 # define gzopen z_gzopen
jonathonfletcher 0:54f5be781526 79 # define gzopen64 z_gzopen64
jonathonfletcher 0:54f5be781526 80 # ifdef _WIN32
jonathonfletcher 0:54f5be781526 81 # define gzopen_w z_gzopen_w
jonathonfletcher 0:54f5be781526 82 # endif
jonathonfletcher 0:54f5be781526 83 # define gzprintf z_gzprintf
jonathonfletcher 0:54f5be781526 84 # define gzputc z_gzputc
jonathonfletcher 0:54f5be781526 85 # define gzputs z_gzputs
jonathonfletcher 0:54f5be781526 86 # define gzread z_gzread
jonathonfletcher 0:54f5be781526 87 # define gzrewind z_gzrewind
jonathonfletcher 0:54f5be781526 88 # define gzseek z_gzseek
jonathonfletcher 0:54f5be781526 89 # define gzseek64 z_gzseek64
jonathonfletcher 0:54f5be781526 90 # define gzsetparams z_gzsetparams
jonathonfletcher 0:54f5be781526 91 # define gztell z_gztell
jonathonfletcher 0:54f5be781526 92 # define gztell64 z_gztell64
jonathonfletcher 0:54f5be781526 93 # define gzungetc z_gzungetc
jonathonfletcher 0:54f5be781526 94 # define gzwrite z_gzwrite
jonathonfletcher 0:54f5be781526 95 # endif
jonathonfletcher 0:54f5be781526 96 # define inflate z_inflate
jonathonfletcher 0:54f5be781526 97 # define inflateBack z_inflateBack
jonathonfletcher 0:54f5be781526 98 # define inflateBackEnd z_inflateBackEnd
jonathonfletcher 0:54f5be781526 99 # define inflateBackInit_ z_inflateBackInit_
jonathonfletcher 0:54f5be781526 100 # define inflateCopy z_inflateCopy
jonathonfletcher 0:54f5be781526 101 # define inflateEnd z_inflateEnd
jonathonfletcher 0:54f5be781526 102 # define inflateGetHeader z_inflateGetHeader
jonathonfletcher 0:54f5be781526 103 # define inflateInit2_ z_inflateInit2_
jonathonfletcher 0:54f5be781526 104 # define inflateInit_ z_inflateInit_
jonathonfletcher 0:54f5be781526 105 # define inflateMark z_inflateMark
jonathonfletcher 0:54f5be781526 106 # define inflatePrime z_inflatePrime
jonathonfletcher 0:54f5be781526 107 # define inflateReset z_inflateReset
jonathonfletcher 0:54f5be781526 108 # define inflateReset2 z_inflateReset2
jonathonfletcher 0:54f5be781526 109 # define inflateSetDictionary z_inflateSetDictionary
jonathonfletcher 0:54f5be781526 110 # define inflateSync z_inflateSync
jonathonfletcher 0:54f5be781526 111 # define inflateSyncPoint z_inflateSyncPoint
jonathonfletcher 0:54f5be781526 112 # define inflateUndermine z_inflateUndermine
jonathonfletcher 0:54f5be781526 113 # define inflateResetKeep z_inflateResetKeep
jonathonfletcher 0:54f5be781526 114 # define inflate_copyright z_inflate_copyright
jonathonfletcher 0:54f5be781526 115 # define inflate_fast z_inflate_fast
jonathonfletcher 0:54f5be781526 116 # define inflate_table z_inflate_table
jonathonfletcher 0:54f5be781526 117 # ifndef Z_SOLO
jonathonfletcher 0:54f5be781526 118 # define uncompress z_uncompress
jonathonfletcher 0:54f5be781526 119 # endif
jonathonfletcher 0:54f5be781526 120 # define zError z_zError
jonathonfletcher 0:54f5be781526 121 # ifndef Z_SOLO
jonathonfletcher 0:54f5be781526 122 # define zcalloc z_zcalloc
jonathonfletcher 0:54f5be781526 123 # define zcfree z_zcfree
jonathonfletcher 0:54f5be781526 124 # endif
jonathonfletcher 0:54f5be781526 125 # define zlibCompileFlags z_zlibCompileFlags
jonathonfletcher 0:54f5be781526 126 # define zlibVersion z_zlibVersion
jonathonfletcher 0:54f5be781526 127
jonathonfletcher 0:54f5be781526 128 /* all zlib typedefs in zlib.h and zconf.h */
jonathonfletcher 0:54f5be781526 129 # define Byte z_Byte
jonathonfletcher 0:54f5be781526 130 # define Bytef z_Bytef
jonathonfletcher 0:54f5be781526 131 # define alloc_func z_alloc_func
jonathonfletcher 0:54f5be781526 132 # define charf z_charf
jonathonfletcher 0:54f5be781526 133 # define free_func z_free_func
jonathonfletcher 0:54f5be781526 134 # ifndef Z_SOLO
jonathonfletcher 0:54f5be781526 135 # define gzFile z_gzFile
jonathonfletcher 0:54f5be781526 136 # endif
jonathonfletcher 0:54f5be781526 137 # define gz_header z_gz_header
jonathonfletcher 0:54f5be781526 138 # define gz_headerp z_gz_headerp
jonathonfletcher 0:54f5be781526 139 # define in_func z_in_func
jonathonfletcher 0:54f5be781526 140 # define intf z_intf
jonathonfletcher 0:54f5be781526 141 # define out_func z_out_func
jonathonfletcher 0:54f5be781526 142 # define uInt z_uInt
jonathonfletcher 0:54f5be781526 143 # define uIntf z_uIntf
jonathonfletcher 0:54f5be781526 144 # define uLong z_uLong
jonathonfletcher 0:54f5be781526 145 # define uLongf z_uLongf
jonathonfletcher 0:54f5be781526 146 # define voidp z_voidp
jonathonfletcher 0:54f5be781526 147 # define voidpc z_voidpc
jonathonfletcher 0:54f5be781526 148 # define voidpf z_voidpf
jonathonfletcher 0:54f5be781526 149
jonathonfletcher 0:54f5be781526 150 /* all zlib structs in zlib.h and zconf.h */
jonathonfletcher 0:54f5be781526 151 # define gz_header_s z_gz_header_s
jonathonfletcher 0:54f5be781526 152 # define internal_state z_internal_state
jonathonfletcher 0:54f5be781526 153
jonathonfletcher 0:54f5be781526 154 #endif
jonathonfletcher 0:54f5be781526 155
jonathonfletcher 0:54f5be781526 156 #if defined(__MSDOS__) && !defined(MSDOS)
jonathonfletcher 0:54f5be781526 157 # define MSDOS
jonathonfletcher 0:54f5be781526 158 #endif
jonathonfletcher 0:54f5be781526 159 #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
jonathonfletcher 0:54f5be781526 160 # define OS2
jonathonfletcher 0:54f5be781526 161 #endif
jonathonfletcher 0:54f5be781526 162 #if defined(_WINDOWS) && !defined(WINDOWS)
jonathonfletcher 0:54f5be781526 163 # define WINDOWS
jonathonfletcher 0:54f5be781526 164 #endif
jonathonfletcher 0:54f5be781526 165 #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
jonathonfletcher 0:54f5be781526 166 # ifndef WIN32
jonathonfletcher 0:54f5be781526 167 # define WIN32
jonathonfletcher 0:54f5be781526 168 # endif
jonathonfletcher 0:54f5be781526 169 #endif
jonathonfletcher 0:54f5be781526 170 #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
jonathonfletcher 0:54f5be781526 171 # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
jonathonfletcher 0:54f5be781526 172 # ifndef SYS16BIT
jonathonfletcher 0:54f5be781526 173 # define SYS16BIT
jonathonfletcher 0:54f5be781526 174 # endif
jonathonfletcher 0:54f5be781526 175 # endif
jonathonfletcher 0:54f5be781526 176 #endif
jonathonfletcher 0:54f5be781526 177
jonathonfletcher 0:54f5be781526 178 /*
jonathonfletcher 0:54f5be781526 179 * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
jonathonfletcher 0:54f5be781526 180 * than 64k bytes at a time (needed on systems with 16-bit int).
jonathonfletcher 0:54f5be781526 181 */
jonathonfletcher 0:54f5be781526 182 #ifdef SYS16BIT
jonathonfletcher 0:54f5be781526 183 # define MAXSEG_64K
jonathonfletcher 0:54f5be781526 184 #endif
jonathonfletcher 0:54f5be781526 185 #ifdef MSDOS
jonathonfletcher 0:54f5be781526 186 # define UNALIGNED_OK
jonathonfletcher 0:54f5be781526 187 #endif
jonathonfletcher 0:54f5be781526 188
jonathonfletcher 0:54f5be781526 189 #ifdef __STDC_VERSION__
jonathonfletcher 0:54f5be781526 190 # ifndef STDC
jonathonfletcher 0:54f5be781526 191 # define STDC
jonathonfletcher 0:54f5be781526 192 # endif
jonathonfletcher 0:54f5be781526 193 # if __STDC_VERSION__ >= 199901L
jonathonfletcher 0:54f5be781526 194 # ifndef STDC99
jonathonfletcher 0:54f5be781526 195 # define STDC99
jonathonfletcher 0:54f5be781526 196 # endif
jonathonfletcher 0:54f5be781526 197 # endif
jonathonfletcher 0:54f5be781526 198 #endif
jonathonfletcher 0:54f5be781526 199 #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
jonathonfletcher 0:54f5be781526 200 # define STDC
jonathonfletcher 0:54f5be781526 201 #endif
jonathonfletcher 0:54f5be781526 202 #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
jonathonfletcher 0:54f5be781526 203 # define STDC
jonathonfletcher 0:54f5be781526 204 #endif
jonathonfletcher 0:54f5be781526 205 #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
jonathonfletcher 0:54f5be781526 206 # define STDC
jonathonfletcher 0:54f5be781526 207 #endif
jonathonfletcher 0:54f5be781526 208 #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
jonathonfletcher 0:54f5be781526 209 # define STDC
jonathonfletcher 0:54f5be781526 210 #endif
jonathonfletcher 0:54f5be781526 211
jonathonfletcher 0:54f5be781526 212 #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
jonathonfletcher 0:54f5be781526 213 # define STDC
jonathonfletcher 0:54f5be781526 214 #endif
jonathonfletcher 0:54f5be781526 215
jonathonfletcher 0:54f5be781526 216 #ifndef STDC
jonathonfletcher 0:54f5be781526 217 # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
jonathonfletcher 0:54f5be781526 218 # define const /* note: need a more gentle solution here */
jonathonfletcher 0:54f5be781526 219 # endif
jonathonfletcher 0:54f5be781526 220 #endif
jonathonfletcher 0:54f5be781526 221
jonathonfletcher 0:54f5be781526 222 #if defined(ZLIB_CONST) && !defined(z_const)
jonathonfletcher 0:54f5be781526 223 # define z_const const
jonathonfletcher 0:54f5be781526 224 #else
jonathonfletcher 0:54f5be781526 225 # define z_const
jonathonfletcher 0:54f5be781526 226 #endif
jonathonfletcher 0:54f5be781526 227
jonathonfletcher 0:54f5be781526 228 /* Some Mac compilers merge all .h files incorrectly: */
jonathonfletcher 0:54f5be781526 229 #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
jonathonfletcher 0:54f5be781526 230 # define NO_DUMMY_DECL
jonathonfletcher 0:54f5be781526 231 #endif
jonathonfletcher 0:54f5be781526 232
jonathonfletcher 0:54f5be781526 233 /* Maximum value for memLevel in deflateInit2 */
jonathonfletcher 0:54f5be781526 234 #ifndef MAX_MEM_LEVEL
jonathonfletcher 0:54f5be781526 235 # ifdef MAXSEG_64K
jonathonfletcher 0:54f5be781526 236 # define MAX_MEM_LEVEL 8
jonathonfletcher 0:54f5be781526 237 # else
jonathonfletcher 0:54f5be781526 238 # define MAX_MEM_LEVEL 9
jonathonfletcher 0:54f5be781526 239 # endif
jonathonfletcher 0:54f5be781526 240 #endif
jonathonfletcher 0:54f5be781526 241
jonathonfletcher 0:54f5be781526 242 /* Maximum value for windowBits in deflateInit2 and inflateInit2.
jonathonfletcher 0:54f5be781526 243 * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
jonathonfletcher 0:54f5be781526 244 * created by gzip. (Files created by minigzip can still be extracted by
jonathonfletcher 0:54f5be781526 245 * gzip.)
jonathonfletcher 0:54f5be781526 246 */
jonathonfletcher 0:54f5be781526 247 #ifndef MAX_WBITS
jonathonfletcher 0:54f5be781526 248 # define MAX_WBITS 15 /* 32K LZ77 window */
jonathonfletcher 0:54f5be781526 249 #endif
jonathonfletcher 0:54f5be781526 250
jonathonfletcher 0:54f5be781526 251 /* The memory requirements for deflate are (in bytes):
jonathonfletcher 0:54f5be781526 252 (1 << (windowBits+2)) + (1 << (memLevel+9))
jonathonfletcher 0:54f5be781526 253 that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
jonathonfletcher 0:54f5be781526 254 plus a few kilobytes for small objects. For example, if you want to reduce
jonathonfletcher 0:54f5be781526 255 the default memory requirements from 256K to 128K, compile with
jonathonfletcher 0:54f5be781526 256 make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
jonathonfletcher 0:54f5be781526 257 Of course this will generally degrade compression (there's no free lunch).
jonathonfletcher 0:54f5be781526 258
jonathonfletcher 0:54f5be781526 259 The memory requirements for inflate are (in bytes) 1 << windowBits
jonathonfletcher 0:54f5be781526 260 that is, 32K for windowBits=15 (default value) plus a few kilobytes
jonathonfletcher 0:54f5be781526 261 for small objects.
jonathonfletcher 0:54f5be781526 262 */
jonathonfletcher 0:54f5be781526 263
jonathonfletcher 0:54f5be781526 264 /* Type declarations */
jonathonfletcher 0:54f5be781526 265
jonathonfletcher 0:54f5be781526 266 #ifndef OF /* function prototypes */
jonathonfletcher 0:54f5be781526 267 # ifdef STDC
jonathonfletcher 0:54f5be781526 268 # define OF(args) args
jonathonfletcher 0:54f5be781526 269 # else
jonathonfletcher 0:54f5be781526 270 # define OF(args) ()
jonathonfletcher 0:54f5be781526 271 # endif
jonathonfletcher 0:54f5be781526 272 #endif
jonathonfletcher 0:54f5be781526 273
jonathonfletcher 0:54f5be781526 274 #ifndef Z_ARG /* function prototypes for stdarg */
jonathonfletcher 0:54f5be781526 275 # if defined(STDC) || defined(Z_HAVE_STDARG_H)
jonathonfletcher 0:54f5be781526 276 # define Z_ARG(args) args
jonathonfletcher 0:54f5be781526 277 # else
jonathonfletcher 0:54f5be781526 278 # define Z_ARG(args) ()
jonathonfletcher 0:54f5be781526 279 # endif
jonathonfletcher 0:54f5be781526 280 #endif
jonathonfletcher 0:54f5be781526 281
jonathonfletcher 0:54f5be781526 282 /* The following definitions for FAR are needed only for MSDOS mixed
jonathonfletcher 0:54f5be781526 283 * model programming (small or medium model with some far allocations).
jonathonfletcher 0:54f5be781526 284 * This was tested only with MSC; for other MSDOS compilers you may have
jonathonfletcher 0:54f5be781526 285 * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
jonathonfletcher 0:54f5be781526 286 * just define FAR to be empty.
jonathonfletcher 0:54f5be781526 287 */
jonathonfletcher 0:54f5be781526 288 #ifdef SYS16BIT
jonathonfletcher 0:54f5be781526 289 # if defined(M_I86SM) || defined(M_I86MM)
jonathonfletcher 0:54f5be781526 290 /* MSC small or medium model */
jonathonfletcher 0:54f5be781526 291 # define SMALL_MEDIUM
jonathonfletcher 0:54f5be781526 292 # ifdef _MSC_VER
jonathonfletcher 0:54f5be781526 293 # define FAR _far
jonathonfletcher 0:54f5be781526 294 # else
jonathonfletcher 0:54f5be781526 295 # define FAR far
jonathonfletcher 0:54f5be781526 296 # endif
jonathonfletcher 0:54f5be781526 297 # endif
jonathonfletcher 0:54f5be781526 298 # if (defined(__SMALL__) || defined(__MEDIUM__))
jonathonfletcher 0:54f5be781526 299 /* Turbo C small or medium model */
jonathonfletcher 0:54f5be781526 300 # define SMALL_MEDIUM
jonathonfletcher 0:54f5be781526 301 # ifdef __BORLANDC__
jonathonfletcher 0:54f5be781526 302 # define FAR _far
jonathonfletcher 0:54f5be781526 303 # else
jonathonfletcher 0:54f5be781526 304 # define FAR far
jonathonfletcher 0:54f5be781526 305 # endif
jonathonfletcher 0:54f5be781526 306 # endif
jonathonfletcher 0:54f5be781526 307 #endif
jonathonfletcher 0:54f5be781526 308
jonathonfletcher 0:54f5be781526 309 #if defined(WINDOWS) || defined(WIN32)
jonathonfletcher 0:54f5be781526 310 /* If building or using zlib as a DLL, define ZLIB_DLL.
jonathonfletcher 0:54f5be781526 311 * This is not mandatory, but it offers a little performance increase.
jonathonfletcher 0:54f5be781526 312 */
jonathonfletcher 0:54f5be781526 313 # ifdef ZLIB_DLL
jonathonfletcher 0:54f5be781526 314 # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
jonathonfletcher 0:54f5be781526 315 # ifdef ZLIB_INTERNAL
jonathonfletcher 0:54f5be781526 316 # define ZEXTERN extern __declspec(dllexport)
jonathonfletcher 0:54f5be781526 317 # else
jonathonfletcher 0:54f5be781526 318 # define ZEXTERN extern __declspec(dllimport)
jonathonfletcher 0:54f5be781526 319 # endif
jonathonfletcher 0:54f5be781526 320 # endif
jonathonfletcher 0:54f5be781526 321 # endif /* ZLIB_DLL */
jonathonfletcher 0:54f5be781526 322 /* If building or using zlib with the WINAPI/WINAPIV calling convention,
jonathonfletcher 0:54f5be781526 323 * define ZLIB_WINAPI.
jonathonfletcher 0:54f5be781526 324 * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
jonathonfletcher 0:54f5be781526 325 */
jonathonfletcher 0:54f5be781526 326 # ifdef ZLIB_WINAPI
jonathonfletcher 0:54f5be781526 327 # ifdef FAR
jonathonfletcher 0:54f5be781526 328 # undef FAR
jonathonfletcher 0:54f5be781526 329 # endif
jonathonfletcher 0:54f5be781526 330 # include <windows.h>
jonathonfletcher 0:54f5be781526 331 /* No need for _export, use ZLIB.DEF instead. */
jonathonfletcher 0:54f5be781526 332 /* For complete Windows compatibility, use WINAPI, not __stdcall. */
jonathonfletcher 0:54f5be781526 333 # define ZEXPORT WINAPI
jonathonfletcher 0:54f5be781526 334 # ifdef WIN32
jonathonfletcher 0:54f5be781526 335 # define ZEXPORTVA WINAPIV
jonathonfletcher 0:54f5be781526 336 # else
jonathonfletcher 0:54f5be781526 337 # define ZEXPORTVA FAR CDECL
jonathonfletcher 0:54f5be781526 338 # endif
jonathonfletcher 0:54f5be781526 339 # endif
jonathonfletcher 0:54f5be781526 340 #endif
jonathonfletcher 0:54f5be781526 341
jonathonfletcher 0:54f5be781526 342 #if defined (__BEOS__)
jonathonfletcher 0:54f5be781526 343 # ifdef ZLIB_DLL
jonathonfletcher 0:54f5be781526 344 # ifdef ZLIB_INTERNAL
jonathonfletcher 0:54f5be781526 345 # define ZEXPORT __declspec(dllexport)
jonathonfletcher 0:54f5be781526 346 # define ZEXPORTVA __declspec(dllexport)
jonathonfletcher 0:54f5be781526 347 # else
jonathonfletcher 0:54f5be781526 348 # define ZEXPORT __declspec(dllimport)
jonathonfletcher 0:54f5be781526 349 # define ZEXPORTVA __declspec(dllimport)
jonathonfletcher 0:54f5be781526 350 # endif
jonathonfletcher 0:54f5be781526 351 # endif
jonathonfletcher 0:54f5be781526 352 #endif
jonathonfletcher 0:54f5be781526 353
jonathonfletcher 0:54f5be781526 354 #ifndef ZEXTERN
jonathonfletcher 0:54f5be781526 355 # define ZEXTERN extern
jonathonfletcher 0:54f5be781526 356 #endif
jonathonfletcher 0:54f5be781526 357 #ifndef ZEXPORT
jonathonfletcher 0:54f5be781526 358 # define ZEXPORT
jonathonfletcher 0:54f5be781526 359 #endif
jonathonfletcher 0:54f5be781526 360 #ifndef ZEXPORTVA
jonathonfletcher 0:54f5be781526 361 # define ZEXPORTVA
jonathonfletcher 0:54f5be781526 362 #endif
jonathonfletcher 0:54f5be781526 363
jonathonfletcher 0:54f5be781526 364 #ifndef FAR
jonathonfletcher 0:54f5be781526 365 # define FAR
jonathonfletcher 0:54f5be781526 366 #endif
jonathonfletcher 0:54f5be781526 367
jonathonfletcher 0:54f5be781526 368 #if !defined(__MACTYPES__)
jonathonfletcher 0:54f5be781526 369 typedef unsigned char Byte; /* 8 bits */
jonathonfletcher 0:54f5be781526 370 #endif
jonathonfletcher 0:54f5be781526 371 typedef unsigned int uInt; /* 16 bits or more */
jonathonfletcher 0:54f5be781526 372 typedef unsigned long uLong; /* 32 bits or more */
jonathonfletcher 0:54f5be781526 373
jonathonfletcher 0:54f5be781526 374 #ifdef SMALL_MEDIUM
jonathonfletcher 0:54f5be781526 375 /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
jonathonfletcher 0:54f5be781526 376 # define Bytef Byte FAR
jonathonfletcher 0:54f5be781526 377 #else
jonathonfletcher 0:54f5be781526 378 typedef Byte FAR Bytef;
jonathonfletcher 0:54f5be781526 379 #endif
jonathonfletcher 0:54f5be781526 380 typedef char FAR charf;
jonathonfletcher 0:54f5be781526 381 typedef int FAR intf;
jonathonfletcher 0:54f5be781526 382 typedef uInt FAR uIntf;
jonathonfletcher 0:54f5be781526 383 typedef uLong FAR uLongf;
jonathonfletcher 0:54f5be781526 384
jonathonfletcher 0:54f5be781526 385 #ifdef STDC
jonathonfletcher 0:54f5be781526 386 typedef void const *voidpc;
jonathonfletcher 0:54f5be781526 387 typedef void FAR *voidpf;
jonathonfletcher 0:54f5be781526 388 typedef void *voidp;
jonathonfletcher 0:54f5be781526 389 #else
jonathonfletcher 0:54f5be781526 390 typedef Byte const *voidpc;
jonathonfletcher 0:54f5be781526 391 typedef Byte FAR *voidpf;
jonathonfletcher 0:54f5be781526 392 typedef Byte *voidp;
jonathonfletcher 0:54f5be781526 393 #endif
jonathonfletcher 0:54f5be781526 394
jonathonfletcher 0:54f5be781526 395 /* ./configure may #define Z_U4 here */
jonathonfletcher 0:54f5be781526 396
jonathonfletcher 0:54f5be781526 397 #if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
jonathonfletcher 0:54f5be781526 398 # include <limits.h>
jonathonfletcher 0:54f5be781526 399 # if (UINT_MAX == 0xffffffffUL)
jonathonfletcher 0:54f5be781526 400 # define Z_U4 unsigned
jonathonfletcher 0:54f5be781526 401 # else
jonathonfletcher 0:54f5be781526 402 # if (ULONG_MAX == 0xffffffffUL)
jonathonfletcher 0:54f5be781526 403 # define Z_U4 unsigned long
jonathonfletcher 0:54f5be781526 404 # else
jonathonfletcher 0:54f5be781526 405 # if (USHRT_MAX == 0xffffffffUL)
jonathonfletcher 0:54f5be781526 406 # define Z_U4 unsigned short
jonathonfletcher 0:54f5be781526 407 # endif
jonathonfletcher 0:54f5be781526 408 # endif
jonathonfletcher 0:54f5be781526 409 # endif
jonathonfletcher 0:54f5be781526 410 #endif
jonathonfletcher 0:54f5be781526 411
jonathonfletcher 0:54f5be781526 412 #ifdef Z_U4
jonathonfletcher 0:54f5be781526 413 typedef Z_U4 z_crc_t;
jonathonfletcher 0:54f5be781526 414 #else
jonathonfletcher 0:54f5be781526 415 typedef unsigned long z_crc_t;
jonathonfletcher 0:54f5be781526 416 #endif
jonathonfletcher 0:54f5be781526 417
jonathonfletcher 0:54f5be781526 418 #ifdef HAVE_UNISTD_H /* may be set to #if 1 by ./configure */
jonathonfletcher 0:54f5be781526 419 # define Z_HAVE_UNISTD_H
jonathonfletcher 0:54f5be781526 420 #endif
jonathonfletcher 0:54f5be781526 421
jonathonfletcher 0:54f5be781526 422 #ifdef HAVE_STDARG_H /* may be set to #if 1 by ./configure */
jonathonfletcher 0:54f5be781526 423 # define Z_HAVE_STDARG_H
jonathonfletcher 0:54f5be781526 424 #endif
jonathonfletcher 0:54f5be781526 425
jonathonfletcher 0:54f5be781526 426 #ifdef STDC
jonathonfletcher 0:54f5be781526 427 # ifndef Z_SOLO
jonathonfletcher 0:54f5be781526 428 //# include <sys/types.h> /* for off_t */
jonathonfletcher 0:54f5be781526 429 # endif
jonathonfletcher 0:54f5be781526 430 #endif
jonathonfletcher 0:54f5be781526 431
jonathonfletcher 0:54f5be781526 432 #ifdef _WIN32
jonathonfletcher 0:54f5be781526 433 # include <stddef.h> /* for wchar_t */
jonathonfletcher 0:54f5be781526 434 #endif
jonathonfletcher 0:54f5be781526 435
jonathonfletcher 0:54f5be781526 436 /* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
jonathonfletcher 0:54f5be781526 437 * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
jonathonfletcher 0:54f5be781526 438 * though the former does not conform to the LFS document), but considering
jonathonfletcher 0:54f5be781526 439 * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
jonathonfletcher 0:54f5be781526 440 * equivalently requesting no 64-bit operations
jonathonfletcher 0:54f5be781526 441 */
jonathonfletcher 0:54f5be781526 442 #if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
jonathonfletcher 0:54f5be781526 443 # undef _LARGEFILE64_SOURCE
jonathonfletcher 0:54f5be781526 444 #endif
jonathonfletcher 0:54f5be781526 445
jonathonfletcher 0:54f5be781526 446 #if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
jonathonfletcher 0:54f5be781526 447 # define Z_HAVE_UNISTD_H
jonathonfletcher 0:54f5be781526 448 #endif
jonathonfletcher 0:54f5be781526 449 #ifndef Z_SOLO
jonathonfletcher 0:54f5be781526 450 # if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE)
jonathonfletcher 0:54f5be781526 451 # include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
jonathonfletcher 0:54f5be781526 452 # ifdef VMS
jonathonfletcher 0:54f5be781526 453 # include <unixio.h> /* for off_t */
jonathonfletcher 0:54f5be781526 454 # endif
jonathonfletcher 0:54f5be781526 455 # ifndef z_off_t
jonathonfletcher 0:54f5be781526 456 # define z_off_t off_t
jonathonfletcher 0:54f5be781526 457 # endif
jonathonfletcher 0:54f5be781526 458 # endif
jonathonfletcher 0:54f5be781526 459 #endif
jonathonfletcher 0:54f5be781526 460
jonathonfletcher 0:54f5be781526 461 #if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
jonathonfletcher 0:54f5be781526 462 # define Z_LFS64
jonathonfletcher 0:54f5be781526 463 #endif
jonathonfletcher 0:54f5be781526 464
jonathonfletcher 0:54f5be781526 465 #if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
jonathonfletcher 0:54f5be781526 466 # define Z_LARGE64
jonathonfletcher 0:54f5be781526 467 #endif
jonathonfletcher 0:54f5be781526 468
jonathonfletcher 0:54f5be781526 469 #if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
jonathonfletcher 0:54f5be781526 470 # define Z_WANT64
jonathonfletcher 0:54f5be781526 471 #endif
jonathonfletcher 0:54f5be781526 472
jonathonfletcher 0:54f5be781526 473 #if !defined(SEEK_SET) && !defined(Z_SOLO)
jonathonfletcher 0:54f5be781526 474 # define SEEK_SET 0 /* Seek from beginning of file. */
jonathonfletcher 0:54f5be781526 475 # define SEEK_CUR 1 /* Seek from current position. */
jonathonfletcher 0:54f5be781526 476 # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
jonathonfletcher 0:54f5be781526 477 #endif
jonathonfletcher 0:54f5be781526 478
jonathonfletcher 0:54f5be781526 479 #ifndef z_off_t
jonathonfletcher 0:54f5be781526 480 # define z_off_t long
jonathonfletcher 0:54f5be781526 481 #endif
jonathonfletcher 0:54f5be781526 482
jonathonfletcher 0:54f5be781526 483 #if !defined(_WIN32) && defined(Z_LARGE64)
jonathonfletcher 0:54f5be781526 484 # define z_off64_t off64_t
jonathonfletcher 0:54f5be781526 485 #else
jonathonfletcher 0:54f5be781526 486 # if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
jonathonfletcher 0:54f5be781526 487 # define z_off64_t __int64
jonathonfletcher 0:54f5be781526 488 # else
jonathonfletcher 0:54f5be781526 489 # define z_off64_t z_off_t
jonathonfletcher 0:54f5be781526 490 # endif
jonathonfletcher 0:54f5be781526 491 #endif
jonathonfletcher 0:54f5be781526 492
jonathonfletcher 0:54f5be781526 493 /* MVS linker does not support external names larger than 8 bytes */
jonathonfletcher 0:54f5be781526 494 #if defined(__MVS__)
jonathonfletcher 0:54f5be781526 495 #pragma map(deflateInit_,"DEIN")
jonathonfletcher 0:54f5be781526 496 #pragma map(deflateInit2_,"DEIN2")
jonathonfletcher 0:54f5be781526 497 #pragma map(deflateEnd,"DEEND")
jonathonfletcher 0:54f5be781526 498 #pragma map(deflateBound,"DEBND")
jonathonfletcher 0:54f5be781526 499 #pragma map(inflateInit_,"ININ")
jonathonfletcher 0:54f5be781526 500 #pragma map(inflateInit2_,"ININ2")
jonathonfletcher 0:54f5be781526 501 #pragma map(inflateEnd,"INEND")
jonathonfletcher 0:54f5be781526 502 #pragma map(inflateSync,"INSY")
jonathonfletcher 0:54f5be781526 503 #pragma map(inflateSetDictionary,"INSEDI")
jonathonfletcher 0:54f5be781526 504 #pragma map(compressBound,"CMBND")
jonathonfletcher 0:54f5be781526 505 #pragma map(inflate_table,"INTABL")
jonathonfletcher 0:54f5be781526 506 #pragma map(inflate_fast,"INFA")
jonathonfletcher 0:54f5be781526 507 #pragma map(inflate_copyright,"INCOPY")
jonathonfletcher 0:54f5be781526 508 #endif
jonathonfletcher 0:54f5be781526 509
jonathonfletcher 0:54f5be781526 510 #endif /* ZCONF_H */