blob: ec21b458fccef1885de0334809aa1f6e4a001b8b [file] [log] [blame]
Mike Frysinger99596bd2011-04-08 12:23:30 +00001/* 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 Glassf11478f2019-12-28 10:45:07 -07009#include <hang.h>
Mike Frysinger99596bd2011-04-08 12:23:30 +000010
11#ifndef NO_DUMMY_DECL
12struct internal_state {int dummy;}; /* for buggy compilers */
13#endif
14
15const 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) */
Mike Frysinger99596bd2011-04-08 12:23:30 +000024""};
25
26#ifdef DEBUG
27
28#ifndef verbose
29#define verbose 0
30#endif
31int z_verbose = verbose;
32
33void z_error (m)
34 char *m;
35{
36 fprintf(stderr, "%s\n", m);
Simon Glassf11478f2019-12-28 10:45:07 -070037 hang();
Mike Frysinger99596bd2011-04-08 12:23:30 +000038}
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
Simon Glassa87fc0a2015-09-02 17:24:57 -060046#ifdef __UBOOT__
47#include <malloc.h>
48#else
Mike Frysinger99596bd2011-04-08 12:23:30 +000049#ifndef STDC
50extern voidp malloc OF((uInt size));
51extern voidp calloc OF((uInt items, uInt size));
52extern void free OF((voidpf ptr));
53#endif
Marcel Ziswilerabc574b2015-08-18 13:06:37 +020054#endif
Mike Frysinger99596bd2011-04-08 12:23:30 +000055
Kim Phillips8eb69942012-10-29 13:34:35 +000056voidpf zcalloc(voidpf opaque, unsigned items, unsigned size)
Mike Frysinger99596bd2011-04-08 12:23:30 +000057{
58 if (opaque)
59 items += size - size; /* make compiler happy */
60 return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
61 (voidpf)calloc(items, size);
62}
63
Kim Phillips8eb69942012-10-29 13:34:35 +000064void zcfree(voidpf opaque, voidpf ptr, unsigned nb)
Mike Frysinger99596bd2011-04-08 12:23:30 +000065{
66 free(ptr);
67 if (opaque)
68 return; /* make compiler happy */
69}
70
71#endif /* MY_ZCALLOC */