Mike Frysinger | 99596bd | 2011-04-08 12:23:30 +0000 | [diff] [blame] | 1 | /* zutil.c -- target dependent utility functions for the compression library |
| 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ |
| 5 | |
| 6 | /* @(#) $Id$ */ |
| 7 | |
| 8 | #include "zutil.h" |
| 9 | |
| 10 | #ifndef NO_DUMMY_DECL |
| 11 | struct internal_state {int dummy;}; /* for buggy compilers */ |
| 12 | #endif |
| 13 | |
| 14 | const char * const z_errmsg[10] = { |
| 15 | "need dictionary", /* Z_NEED_DICT 2 */ |
| 16 | "stream end", /* Z_STREAM_END 1 */ |
| 17 | "", /* Z_OK 0 */ |
| 18 | "file error", /* Z_ERRNO (-1) */ |
| 19 | "stream error", /* Z_STREAM_ERROR (-2) */ |
| 20 | "data error", /* Z_DATA_ERROR (-3) */ |
| 21 | "insufficient memory", /* Z_MEM_ERROR (-4) */ |
| 22 | "buffer error", /* Z_BUF_ERROR (-5) */ |
| 23 | "incompatible version",/* Z_VERSION_ERROR (-6) */ |
| 24 | ""}; |
| 25 | |
| 26 | #ifdef DEBUG |
| 27 | |
| 28 | #ifndef verbose |
| 29 | #define verbose 0 |
| 30 | #endif |
| 31 | int z_verbose = verbose; |
| 32 | |
| 33 | void z_error (m) |
| 34 | char *m; |
| 35 | { |
| 36 | fprintf(stderr, "%s\n", m); |
| 37 | hang (); |
| 38 | } |
| 39 | #endif |
| 40 | |
| 41 | /* exported to allow conversion of error code to string for compress() and |
| 42 | * uncompress() |
| 43 | */ |
| 44 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ |
| 45 | |
| 46 | #ifndef STDC |
| 47 | extern voidp malloc OF((uInt size)); |
| 48 | extern voidp calloc OF((uInt items, uInt size)); |
| 49 | extern void free OF((voidpf ptr)); |
| 50 | #endif |
| 51 | |
| 52 | voidpf zcalloc (opaque, items, size) |
| 53 | voidpf opaque; |
| 54 | unsigned items; |
| 55 | unsigned size; |
| 56 | { |
| 57 | if (opaque) |
| 58 | items += size - size; /* make compiler happy */ |
| 59 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : |
| 60 | (voidpf)calloc(items, size); |
| 61 | } |
| 62 | |
| 63 | void zcfree (opaque, ptr, nb) |
| 64 | voidpf opaque; |
| 65 | voidpf ptr; |
| 66 | unsigned nb; |
| 67 | { |
| 68 | free(ptr); |
| 69 | if (opaque) |
| 70 | return; /* make compiler happy */ |
| 71 | } |
| 72 | |
| 73 | #endif /* MY_ZCALLOC */ |