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" |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 9 | #include <hang.h> |
Mike Frysinger | 99596bd | 2011-04-08 12:23:30 +0000 | [diff] [blame] | 10 | |
| 11 | #ifndef NO_DUMMY_DECL |
| 12 | struct internal_state {int dummy;}; /* for buggy compilers */ |
| 13 | #endif |
| 14 | |
| 15 | const char * const z_errmsg[10] = { |
| 16 | "need dictionary", /* Z_NEED_DICT 2 */ |
| 17 | "stream end", /* Z_STREAM_END 1 */ |
| 18 | "", /* Z_OK 0 */ |
| 19 | "file error", /* Z_ERRNO (-1) */ |
| 20 | "stream error", /* Z_STREAM_ERROR (-2) */ |
| 21 | "data error", /* Z_DATA_ERROR (-3) */ |
| 22 | "insufficient memory", /* Z_MEM_ERROR (-4) */ |
| 23 | "buffer error", /* Z_BUF_ERROR (-5) */ |
Tom Rini | 4eab176 | 2024-06-30 19:03:14 -0600 | [diff] [blame] | 24 | "incompatible version",/* Z_VERSION_ERROR (-6) */ |
Mike Frysinger | 99596bd | 2011-04-08 12:23:30 +0000 | [diff] [blame] | 25 | ""}; |
| 26 | |
| 27 | #ifdef DEBUG |
| 28 | |
| 29 | #ifndef verbose |
| 30 | #define verbose 0 |
| 31 | #endif |
| 32 | int z_verbose = verbose; |
| 33 | |
| 34 | void z_error (m) |
| 35 | char *m; |
| 36 | { |
| 37 | fprintf(stderr, "%s\n", m); |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 38 | hang(); |
Mike Frysinger | 99596bd | 2011-04-08 12:23:30 +0000 | [diff] [blame] | 39 | } |
| 40 | #endif |
| 41 | |
| 42 | /* exported to allow conversion of error code to string for compress() and |
| 43 | * uncompress() |
| 44 | */ |
| 45 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ |
| 46 | |
Simon Glass | a87fc0a | 2015-09-02 17:24:57 -0600 | [diff] [blame] | 47 | #ifdef __UBOOT__ |
| 48 | #include <malloc.h> |
| 49 | #else |
Mike Frysinger | 99596bd | 2011-04-08 12:23:30 +0000 | [diff] [blame] | 50 | #ifndef STDC |
| 51 | extern voidp malloc OF((uInt size)); |
| 52 | extern voidp calloc OF((uInt items, uInt size)); |
| 53 | extern void free OF((voidpf ptr)); |
| 54 | #endif |
Marcel Ziswiler | abc574b | 2015-08-18 13:06:37 +0200 | [diff] [blame] | 55 | #endif |
Mike Frysinger | 99596bd | 2011-04-08 12:23:30 +0000 | [diff] [blame] | 56 | |
Kim Phillips | 8eb6994 | 2012-10-29 13:34:35 +0000 | [diff] [blame] | 57 | voidpf zcalloc(voidpf opaque, unsigned items, unsigned size) |
Mike Frysinger | 99596bd | 2011-04-08 12:23:30 +0000 | [diff] [blame] | 58 | { |
| 59 | if (opaque) |
| 60 | items += size - size; /* make compiler happy */ |
| 61 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : |
| 62 | (voidpf)calloc(items, size); |
| 63 | } |
| 64 | |
Kim Phillips | 8eb6994 | 2012-10-29 13:34:35 +0000 | [diff] [blame] | 65 | void zcfree(voidpf opaque, voidpf ptr, unsigned nb) |
Mike Frysinger | 99596bd | 2011-04-08 12:23:30 +0000 | [diff] [blame] | 66 | { |
| 67 | free(ptr); |
| 68 | if (opaque) |
| 69 | return; /* make compiler happy */ |
| 70 | } |
| 71 | |
| 72 | #endif /* MY_ZCALLOC */ |