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 /* zutil.c -- target dependent utility functions for the compression library
jonathonfletcher 0:54f5be781526 2 * Copyright (C) 1995-2005, 2010, 2011, 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 #include "zutil.h"
jonathonfletcher 0:54f5be781526 9 #ifndef Z_SOLO
jonathonfletcher 0:54f5be781526 10 # include "gzguts.h"
jonathonfletcher 0:54f5be781526 11 #endif
jonathonfletcher 0:54f5be781526 12
jonathonfletcher 0:54f5be781526 13 #ifndef NO_DUMMY_DECL
jonathonfletcher 0:54f5be781526 14 struct internal_state {int dummy;}; /* for buggy compilers */
jonathonfletcher 0:54f5be781526 15 #endif
jonathonfletcher 0:54f5be781526 16
jonathonfletcher 0:54f5be781526 17 const char * const z_errmsg[10] = {
jonathonfletcher 0:54f5be781526 18 "need dictionary", /* Z_NEED_DICT 2 */
jonathonfletcher 0:54f5be781526 19 "stream end", /* Z_STREAM_END 1 */
jonathonfletcher 0:54f5be781526 20 "", /* Z_OK 0 */
jonathonfletcher 0:54f5be781526 21 "file error", /* Z_ERRNO (-1) */
jonathonfletcher 0:54f5be781526 22 "stream error", /* Z_STREAM_ERROR (-2) */
jonathonfletcher 0:54f5be781526 23 "data error", /* Z_DATA_ERROR (-3) */
jonathonfletcher 0:54f5be781526 24 "insufficient memory", /* Z_MEM_ERROR (-4) */
jonathonfletcher 0:54f5be781526 25 "buffer error", /* Z_BUF_ERROR (-5) */
jonathonfletcher 0:54f5be781526 26 "incompatible version",/* Z_VERSION_ERROR (-6) */
jonathonfletcher 0:54f5be781526 27 ""};
jonathonfletcher 0:54f5be781526 28
jonathonfletcher 0:54f5be781526 29
jonathonfletcher 0:54f5be781526 30 const char * ZEXPORT zlibVersion()
jonathonfletcher 0:54f5be781526 31 {
jonathonfletcher 0:54f5be781526 32 return ZLIB_VERSION;
jonathonfletcher 0:54f5be781526 33 }
jonathonfletcher 0:54f5be781526 34
jonathonfletcher 0:54f5be781526 35 uLong ZEXPORT zlibCompileFlags()
jonathonfletcher 0:54f5be781526 36 {
jonathonfletcher 0:54f5be781526 37 uLong flags;
jonathonfletcher 0:54f5be781526 38
jonathonfletcher 0:54f5be781526 39 flags = 0;
jonathonfletcher 0:54f5be781526 40 switch ((int)(sizeof(uInt))) {
jonathonfletcher 0:54f5be781526 41 case 2: break;
jonathonfletcher 0:54f5be781526 42 case 4: flags += 1; break;
jonathonfletcher 0:54f5be781526 43 case 8: flags += 2; break;
jonathonfletcher 0:54f5be781526 44 default: flags += 3;
jonathonfletcher 0:54f5be781526 45 }
jonathonfletcher 0:54f5be781526 46 switch ((int)(sizeof(uLong))) {
jonathonfletcher 0:54f5be781526 47 case 2: break;
jonathonfletcher 0:54f5be781526 48 case 4: flags += 1 << 2; break;
jonathonfletcher 0:54f5be781526 49 case 8: flags += 2 << 2; break;
jonathonfletcher 0:54f5be781526 50 default: flags += 3 << 2;
jonathonfletcher 0:54f5be781526 51 }
jonathonfletcher 0:54f5be781526 52 switch ((int)(sizeof(voidpf))) {
jonathonfletcher 0:54f5be781526 53 case 2: break;
jonathonfletcher 0:54f5be781526 54 case 4: flags += 1 << 4; break;
jonathonfletcher 0:54f5be781526 55 case 8: flags += 2 << 4; break;
jonathonfletcher 0:54f5be781526 56 default: flags += 3 << 4;
jonathonfletcher 0:54f5be781526 57 }
jonathonfletcher 0:54f5be781526 58 switch ((int)(sizeof(z_off_t))) {
jonathonfletcher 0:54f5be781526 59 case 2: break;
jonathonfletcher 0:54f5be781526 60 case 4: flags += 1 << 6; break;
jonathonfletcher 0:54f5be781526 61 case 8: flags += 2 << 6; break;
jonathonfletcher 0:54f5be781526 62 default: flags += 3 << 6;
jonathonfletcher 0:54f5be781526 63 }
jonathonfletcher 0:54f5be781526 64 #ifdef DEBUG
jonathonfletcher 0:54f5be781526 65 flags += 1 << 8;
jonathonfletcher 0:54f5be781526 66 #endif
jonathonfletcher 0:54f5be781526 67 #if defined(ASMV) || defined(ASMINF)
jonathonfletcher 0:54f5be781526 68 flags += 1 << 9;
jonathonfletcher 0:54f5be781526 69 #endif
jonathonfletcher 0:54f5be781526 70 #ifdef ZLIB_WINAPI
jonathonfletcher 0:54f5be781526 71 flags += 1 << 10;
jonathonfletcher 0:54f5be781526 72 #endif
jonathonfletcher 0:54f5be781526 73 #ifdef BUILDFIXED
jonathonfletcher 0:54f5be781526 74 flags += 1 << 12;
jonathonfletcher 0:54f5be781526 75 #endif
jonathonfletcher 0:54f5be781526 76 #ifdef DYNAMIC_CRC_TABLE
jonathonfletcher 0:54f5be781526 77 flags += 1 << 13;
jonathonfletcher 0:54f5be781526 78 #endif
jonathonfletcher 0:54f5be781526 79 #ifdef NO_GZCOMPRESS
jonathonfletcher 0:54f5be781526 80 flags += 1L << 16;
jonathonfletcher 0:54f5be781526 81 #endif
jonathonfletcher 0:54f5be781526 82 #ifdef NO_GZIP
jonathonfletcher 0:54f5be781526 83 flags += 1L << 17;
jonathonfletcher 0:54f5be781526 84 #endif
jonathonfletcher 0:54f5be781526 85 #ifdef PKZIP_BUG_WORKAROUND
jonathonfletcher 0:54f5be781526 86 flags += 1L << 20;
jonathonfletcher 0:54f5be781526 87 #endif
jonathonfletcher 0:54f5be781526 88 #ifdef FASTEST
jonathonfletcher 0:54f5be781526 89 flags += 1L << 21;
jonathonfletcher 0:54f5be781526 90 #endif
jonathonfletcher 0:54f5be781526 91 #if defined(STDC) || defined(Z_HAVE_STDARG_H)
jonathonfletcher 0:54f5be781526 92 # ifdef NO_vsnprintf
jonathonfletcher 0:54f5be781526 93 flags += 1L << 25;
jonathonfletcher 0:54f5be781526 94 # ifdef HAS_vsprintf_void
jonathonfletcher 0:54f5be781526 95 flags += 1L << 26;
jonathonfletcher 0:54f5be781526 96 # endif
jonathonfletcher 0:54f5be781526 97 # else
jonathonfletcher 0:54f5be781526 98 # ifdef HAS_vsnprintf_void
jonathonfletcher 0:54f5be781526 99 flags += 1L << 26;
jonathonfletcher 0:54f5be781526 100 # endif
jonathonfletcher 0:54f5be781526 101 # endif
jonathonfletcher 0:54f5be781526 102 #else
jonathonfletcher 0:54f5be781526 103 flags += 1L << 24;
jonathonfletcher 0:54f5be781526 104 # ifdef NO_snprintf
jonathonfletcher 0:54f5be781526 105 flags += 1L << 25;
jonathonfletcher 0:54f5be781526 106 # ifdef HAS_sprintf_void
jonathonfletcher 0:54f5be781526 107 flags += 1L << 26;
jonathonfletcher 0:54f5be781526 108 # endif
jonathonfletcher 0:54f5be781526 109 # else
jonathonfletcher 0:54f5be781526 110 # ifdef HAS_snprintf_void
jonathonfletcher 0:54f5be781526 111 flags += 1L << 26;
jonathonfletcher 0:54f5be781526 112 # endif
jonathonfletcher 0:54f5be781526 113 # endif
jonathonfletcher 0:54f5be781526 114 #endif
jonathonfletcher 0:54f5be781526 115 return flags;
jonathonfletcher 0:54f5be781526 116 }
jonathonfletcher 0:54f5be781526 117
jonathonfletcher 0:54f5be781526 118 #ifdef DEBUG
jonathonfletcher 0:54f5be781526 119
jonathonfletcher 0:54f5be781526 120 # ifndef verbose
jonathonfletcher 0:54f5be781526 121 # define verbose 0
jonathonfletcher 0:54f5be781526 122 # endif
jonathonfletcher 0:54f5be781526 123 int ZLIB_INTERNAL z_verbose = verbose;
jonathonfletcher 0:54f5be781526 124
jonathonfletcher 0:54f5be781526 125 void ZLIB_INTERNAL z_error (m)
jonathonfletcher 0:54f5be781526 126 char *m;
jonathonfletcher 0:54f5be781526 127 {
jonathonfletcher 0:54f5be781526 128 fprintf(stderr, "%s\n", m);
jonathonfletcher 0:54f5be781526 129 exit(1);
jonathonfletcher 0:54f5be781526 130 }
jonathonfletcher 0:54f5be781526 131 #endif
jonathonfletcher 0:54f5be781526 132
jonathonfletcher 0:54f5be781526 133 /* exported to allow conversion of error code to string for compress() and
jonathonfletcher 0:54f5be781526 134 * uncompress()
jonathonfletcher 0:54f5be781526 135 */
jonathonfletcher 0:54f5be781526 136 const char * ZEXPORT zError(err)
jonathonfletcher 0:54f5be781526 137 int err;
jonathonfletcher 0:54f5be781526 138 {
jonathonfletcher 0:54f5be781526 139 return ERR_MSG(err);
jonathonfletcher 0:54f5be781526 140 }
jonathonfletcher 0:54f5be781526 141
jonathonfletcher 0:54f5be781526 142 #if defined(_WIN32_WCE)
jonathonfletcher 0:54f5be781526 143 /* The Microsoft C Run-Time Library for Windows CE doesn't have
jonathonfletcher 0:54f5be781526 144 * errno. We define it as a global variable to simplify porting.
jonathonfletcher 0:54f5be781526 145 * Its value is always 0 and should not be used.
jonathonfletcher 0:54f5be781526 146 */
jonathonfletcher 0:54f5be781526 147 int errno = 0;
jonathonfletcher 0:54f5be781526 148 #endif
jonathonfletcher 0:54f5be781526 149
jonathonfletcher 0:54f5be781526 150 #ifndef HAVE_MEMCPY
jonathonfletcher 0:54f5be781526 151
jonathonfletcher 0:54f5be781526 152 void ZLIB_INTERNAL zmemcpy(dest, source, len)
jonathonfletcher 0:54f5be781526 153 Bytef* dest;
jonathonfletcher 0:54f5be781526 154 const Bytef* source;
jonathonfletcher 0:54f5be781526 155 uInt len;
jonathonfletcher 0:54f5be781526 156 {
jonathonfletcher 0:54f5be781526 157 if (len == 0) return;
jonathonfletcher 0:54f5be781526 158 do {
jonathonfletcher 0:54f5be781526 159 *dest++ = *source++; /* ??? to be unrolled */
jonathonfletcher 0:54f5be781526 160 } while (--len != 0);
jonathonfletcher 0:54f5be781526 161 }
jonathonfletcher 0:54f5be781526 162
jonathonfletcher 0:54f5be781526 163 int ZLIB_INTERNAL zmemcmp(s1, s2, len)
jonathonfletcher 0:54f5be781526 164 const Bytef* s1;
jonathonfletcher 0:54f5be781526 165 const Bytef* s2;
jonathonfletcher 0:54f5be781526 166 uInt len;
jonathonfletcher 0:54f5be781526 167 {
jonathonfletcher 0:54f5be781526 168 uInt j;
jonathonfletcher 0:54f5be781526 169
jonathonfletcher 0:54f5be781526 170 for (j = 0; j < len; j++) {
jonathonfletcher 0:54f5be781526 171 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
jonathonfletcher 0:54f5be781526 172 }
jonathonfletcher 0:54f5be781526 173 return 0;
jonathonfletcher 0:54f5be781526 174 }
jonathonfletcher 0:54f5be781526 175
jonathonfletcher 0:54f5be781526 176 void ZLIB_INTERNAL zmemzero(dest, len)
jonathonfletcher 0:54f5be781526 177 Bytef* dest;
jonathonfletcher 0:54f5be781526 178 uInt len;
jonathonfletcher 0:54f5be781526 179 {
jonathonfletcher 0:54f5be781526 180 if (len == 0) return;
jonathonfletcher 0:54f5be781526 181 do {
jonathonfletcher 0:54f5be781526 182 *dest++ = 0; /* ??? to be unrolled */
jonathonfletcher 0:54f5be781526 183 } while (--len != 0);
jonathonfletcher 0:54f5be781526 184 }
jonathonfletcher 0:54f5be781526 185 #endif
jonathonfletcher 0:54f5be781526 186
jonathonfletcher 0:54f5be781526 187 #ifndef Z_SOLO
jonathonfletcher 0:54f5be781526 188
jonathonfletcher 0:54f5be781526 189 #ifdef SYS16BIT
jonathonfletcher 0:54f5be781526 190
jonathonfletcher 0:54f5be781526 191 #ifdef __TURBOC__
jonathonfletcher 0:54f5be781526 192 /* Turbo C in 16-bit mode */
jonathonfletcher 0:54f5be781526 193
jonathonfletcher 0:54f5be781526 194 # define MY_ZCALLOC
jonathonfletcher 0:54f5be781526 195
jonathonfletcher 0:54f5be781526 196 /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
jonathonfletcher 0:54f5be781526 197 * and farmalloc(64K) returns a pointer with an offset of 8, so we
jonathonfletcher 0:54f5be781526 198 * must fix the pointer. Warning: the pointer must be put back to its
jonathonfletcher 0:54f5be781526 199 * original form in order to free it, use zcfree().
jonathonfletcher 0:54f5be781526 200 */
jonathonfletcher 0:54f5be781526 201
jonathonfletcher 0:54f5be781526 202 #define MAX_PTR 10
jonathonfletcher 0:54f5be781526 203 /* 10*64K = 640K */
jonathonfletcher 0:54f5be781526 204
jonathonfletcher 0:54f5be781526 205 local int next_ptr = 0;
jonathonfletcher 0:54f5be781526 206
jonathonfletcher 0:54f5be781526 207 typedef struct ptr_table_s {
jonathonfletcher 0:54f5be781526 208 voidpf org_ptr;
jonathonfletcher 0:54f5be781526 209 voidpf new_ptr;
jonathonfletcher 0:54f5be781526 210 } ptr_table;
jonathonfletcher 0:54f5be781526 211
jonathonfletcher 0:54f5be781526 212 local ptr_table table[MAX_PTR];
jonathonfletcher 0:54f5be781526 213 /* This table is used to remember the original form of pointers
jonathonfletcher 0:54f5be781526 214 * to large buffers (64K). Such pointers are normalized with a zero offset.
jonathonfletcher 0:54f5be781526 215 * Since MSDOS is not a preemptive multitasking OS, this table is not
jonathonfletcher 0:54f5be781526 216 * protected from concurrent access. This hack doesn't work anyway on
jonathonfletcher 0:54f5be781526 217 * a protected system like OS/2. Use Microsoft C instead.
jonathonfletcher 0:54f5be781526 218 */
jonathonfletcher 0:54f5be781526 219
jonathonfletcher 0:54f5be781526 220 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
jonathonfletcher 0:54f5be781526 221 {
jonathonfletcher 0:54f5be781526 222 voidpf buf = opaque; /* just to make some compilers happy */
jonathonfletcher 0:54f5be781526 223 ulg bsize = (ulg)items*size;
jonathonfletcher 0:54f5be781526 224
jonathonfletcher 0:54f5be781526 225 /* If we allocate less than 65520 bytes, we assume that farmalloc
jonathonfletcher 0:54f5be781526 226 * will return a usable pointer which doesn't have to be normalized.
jonathonfletcher 0:54f5be781526 227 */
jonathonfletcher 0:54f5be781526 228 if (bsize < 65520L) {
jonathonfletcher 0:54f5be781526 229 buf = farmalloc(bsize);
jonathonfletcher 0:54f5be781526 230 if (*(ush*)&buf != 0) return buf;
jonathonfletcher 0:54f5be781526 231 } else {
jonathonfletcher 0:54f5be781526 232 buf = farmalloc(bsize + 16L);
jonathonfletcher 0:54f5be781526 233 }
jonathonfletcher 0:54f5be781526 234 if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
jonathonfletcher 0:54f5be781526 235 table[next_ptr].org_ptr = buf;
jonathonfletcher 0:54f5be781526 236
jonathonfletcher 0:54f5be781526 237 /* Normalize the pointer to seg:0 */
jonathonfletcher 0:54f5be781526 238 *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
jonathonfletcher 0:54f5be781526 239 *(ush*)&buf = 0;
jonathonfletcher 0:54f5be781526 240 table[next_ptr++].new_ptr = buf;
jonathonfletcher 0:54f5be781526 241 return buf;
jonathonfletcher 0:54f5be781526 242 }
jonathonfletcher 0:54f5be781526 243
jonathonfletcher 0:54f5be781526 244 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
jonathonfletcher 0:54f5be781526 245 {
jonathonfletcher 0:54f5be781526 246 int n;
jonathonfletcher 0:54f5be781526 247 if (*(ush*)&ptr != 0) { /* object < 64K */
jonathonfletcher 0:54f5be781526 248 farfree(ptr);
jonathonfletcher 0:54f5be781526 249 return;
jonathonfletcher 0:54f5be781526 250 }
jonathonfletcher 0:54f5be781526 251 /* Find the original pointer */
jonathonfletcher 0:54f5be781526 252 for (n = 0; n < next_ptr; n++) {
jonathonfletcher 0:54f5be781526 253 if (ptr != table[n].new_ptr) continue;
jonathonfletcher 0:54f5be781526 254
jonathonfletcher 0:54f5be781526 255 farfree(table[n].org_ptr);
jonathonfletcher 0:54f5be781526 256 while (++n < next_ptr) {
jonathonfletcher 0:54f5be781526 257 table[n-1] = table[n];
jonathonfletcher 0:54f5be781526 258 }
jonathonfletcher 0:54f5be781526 259 next_ptr--;
jonathonfletcher 0:54f5be781526 260 return;
jonathonfletcher 0:54f5be781526 261 }
jonathonfletcher 0:54f5be781526 262 ptr = opaque; /* just to make some compilers happy */
jonathonfletcher 0:54f5be781526 263 Assert(0, "zcfree: ptr not found");
jonathonfletcher 0:54f5be781526 264 }
jonathonfletcher 0:54f5be781526 265
jonathonfletcher 0:54f5be781526 266 #endif /* __TURBOC__ */
jonathonfletcher 0:54f5be781526 267
jonathonfletcher 0:54f5be781526 268
jonathonfletcher 0:54f5be781526 269 #ifdef M_I86
jonathonfletcher 0:54f5be781526 270 /* Microsoft C in 16-bit mode */
jonathonfletcher 0:54f5be781526 271
jonathonfletcher 0:54f5be781526 272 # define MY_ZCALLOC
jonathonfletcher 0:54f5be781526 273
jonathonfletcher 0:54f5be781526 274 #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
jonathonfletcher 0:54f5be781526 275 # define _halloc halloc
jonathonfletcher 0:54f5be781526 276 # define _hfree hfree
jonathonfletcher 0:54f5be781526 277 #endif
jonathonfletcher 0:54f5be781526 278
jonathonfletcher 0:54f5be781526 279 voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
jonathonfletcher 0:54f5be781526 280 {
jonathonfletcher 0:54f5be781526 281 if (opaque) opaque = 0; /* to make compiler happy */
jonathonfletcher 0:54f5be781526 282 return _halloc((long)items, size);
jonathonfletcher 0:54f5be781526 283 }
jonathonfletcher 0:54f5be781526 284
jonathonfletcher 0:54f5be781526 285 void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
jonathonfletcher 0:54f5be781526 286 {
jonathonfletcher 0:54f5be781526 287 if (opaque) opaque = 0; /* to make compiler happy */
jonathonfletcher 0:54f5be781526 288 _hfree(ptr);
jonathonfletcher 0:54f5be781526 289 }
jonathonfletcher 0:54f5be781526 290
jonathonfletcher 0:54f5be781526 291 #endif /* M_I86 */
jonathonfletcher 0:54f5be781526 292
jonathonfletcher 0:54f5be781526 293 #endif /* SYS16BIT */
jonathonfletcher 0:54f5be781526 294
jonathonfletcher 0:54f5be781526 295
jonathonfletcher 0:54f5be781526 296 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
jonathonfletcher 0:54f5be781526 297
jonathonfletcher 0:54f5be781526 298 #ifndef STDC
jonathonfletcher 0:54f5be781526 299 extern voidp malloc OF((uInt size));
jonathonfletcher 0:54f5be781526 300 extern voidp calloc OF((uInt items, uInt size));
jonathonfletcher 0:54f5be781526 301 extern void free OF((voidpf ptr));
jonathonfletcher 0:54f5be781526 302 #endif
jonathonfletcher 0:54f5be781526 303
jonathonfletcher 0:54f5be781526 304 voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
jonathonfletcher 0:54f5be781526 305 voidpf opaque;
jonathonfletcher 0:54f5be781526 306 unsigned items;
jonathonfletcher 0:54f5be781526 307 unsigned size;
jonathonfletcher 0:54f5be781526 308 {
jonathonfletcher 0:54f5be781526 309 if (opaque) items += size - size; /* make compiler happy */
jonathonfletcher 0:54f5be781526 310 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
jonathonfletcher 0:54f5be781526 311 (voidpf)calloc(items, size);
jonathonfletcher 0:54f5be781526 312 }
jonathonfletcher 0:54f5be781526 313
jonathonfletcher 0:54f5be781526 314 void ZLIB_INTERNAL zcfree (opaque, ptr)
jonathonfletcher 0:54f5be781526 315 voidpf opaque;
jonathonfletcher 0:54f5be781526 316 voidpf ptr;
jonathonfletcher 0:54f5be781526 317 {
jonathonfletcher 0:54f5be781526 318 free(ptr);
jonathonfletcher 0:54f5be781526 319 if (opaque) return; /* make compiler happy */
jonathonfletcher 0:54f5be781526 320 }
jonathonfletcher 0:54f5be781526 321
jonathonfletcher 0:54f5be781526 322 #endif /* MY_ZCALLOC */
jonathonfletcher 0:54f5be781526 323
jonathonfletcher 0:54f5be781526 324 #endif /* !Z_SOLO */