1/* zutil.c -- target dependent utility functions for the compression library
2 * Copyright (C) 1995-2017 Jean-loup Gailly
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zbuild.h"
7#include "zutil_p.h"
8#include "zutil.h"
9
10z_const char * const PREFIX(z_errmsg)[10] = {
11 (z_const char *)"need dictionary", /* Z_NEED_DICT 2 */
12 (z_const char *)"stream end", /* Z_STREAM_END 1 */
13 (z_const char *)"", /* Z_OK 0 */
14 (z_const char *)"file error", /* Z_ERRNO (-1) */
15 (z_const char *)"stream error", /* Z_STREAM_ERROR (-2) */
16 (z_const char *)"data error", /* Z_DATA_ERROR (-3) */
17 (z_const char *)"insufficient memory", /* Z_MEM_ERROR (-4) */
18 (z_const char *)"buffer error", /* Z_BUF_ERROR (-5) */
19 (z_const char *)"incompatible version",/* Z_VERSION_ERROR (-6) */
20 (z_const char *)""
21};
22
23const char zlibng_string[] =
24 " zlib-ng 2.0.6 forked from zlib";
25
26#ifdef ZLIB_COMPAT
27const char * Z_EXPORT zlibVersion(void) {
28 return ZLIB_VERSION;
29}
30#endif
31
32const char * Z_EXPORT zlibng_version(void) {
33 return ZLIBNG_VERSION;
34}
35
36unsigned long Z_EXPORT PREFIX(zlibCompileFlags)(void) {
37 unsigned long flags;
38
39 flags = 0;
40 switch ((int)(sizeof(unsigned int))) {
41 case 2: break;
42 case 4: flags += 1; break;
43 case 8: flags += 2; break;
44 default: flags += 3;
45 }
46 switch ((int)(sizeof(unsigned long))) {
47 case 2: break;
48 case 4: flags += 1 << 2; break;
49 case 8: flags += 2 << 2; break;
50 default: flags += 3 << 2;
51 }
52 switch ((int)(sizeof(void *))) {
53 case 2: break;
54 case 4: flags += 1 << 4; break;
55 case 8: flags += 2 << 4; break;
56 default: flags += 3 << 4;
57 }
58 switch ((int)(sizeof(z_off_t))) {
59 case 2: break;
60 case 4: flags += 1 << 6; break;
61 case 8: flags += 2 << 6; break;
62 default: flags += 3 << 6;
63 }
64#ifdef ZLIB_DEBUG
65 flags += 1 << 8;
66#endif
67#ifdef ZLIB_WINAPI
68 flags += 1 << 10;
69#endif
70 /* Bit 13 reserved for DYNAMIC_CRC_TABLE */
71#ifdef NO_GZCOMPRESS
72 flags += 1L << 16;
73#endif
74#ifdef NO_GZIP
75 flags += 1L << 17;
76#endif
77#ifdef PKZIP_BUG_WORKAROUND
78 flags += 1L << 20;
79#endif
80 return flags;
81}
82
83#ifdef ZLIB_DEBUG
84# include <stdlib.h>
85# ifndef verbose
86# define verbose 0
87# endif
88int Z_INTERNAL z_verbose = verbose;
89
90void Z_INTERNAL z_error(char *m) {
91 fprintf(stderr, "%s\n", m);
92 exit(1);
93}
94#endif
95
96/* exported to allow conversion of error code to string for compress() and
97 * uncompress()
98 */
99const char * Z_EXPORT PREFIX(zError)(int err) {
100 return ERR_MSG(err);
101}
102
103void Z_INTERNAL *zng_calloc(void *opaque, unsigned items, unsigned size) {
104 Z_UNUSED(opaque);
105 return zng_alloc(size: (size_t)items * (size_t)size);
106}
107
108void Z_INTERNAL zng_cfree(void *opaque, void *ptr) {
109 Z_UNUSED(opaque);
110 zng_free(ptr);
111}
112