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 | /* @(#) $Id$ */ |
7 | |
8 | #include "zbuild.h" |
9 | #include "zutil.h" |
10 | #ifdef WITH_GZFILEOP |
11 | # include "gzguts.h" |
12 | #endif |
13 | #ifndef UNALIGNED_OK |
14 | # include "malloc.h" |
15 | #endif |
16 | |
17 | const char * const zng_errmsg[10] = { |
18 | (const char *)"need dictionary" , /* Z_NEED_DICT 2 */ |
19 | (const char *)"stream end" , /* Z_STREAM_END 1 */ |
20 | (const char *)"" , /* Z_OK 0 */ |
21 | (const char *)"file error" , /* Z_ERRNO (-1) */ |
22 | (const char *)"stream error" , /* Z_STREAM_ERROR (-2) */ |
23 | (const char *)"data error" , /* Z_DATA_ERROR (-3) */ |
24 | (const char *)"insufficient memory" , /* Z_MEM_ERROR (-4) */ |
25 | (const char *)"buffer error" , /* Z_BUF_ERROR (-5) */ |
26 | (const char *)"incompatible version" ,/* Z_VERSION_ERROR (-6) */ |
27 | (const char *)"" |
28 | }; |
29 | |
30 | const char zlibng_string[] = |
31 | " zlib-ng 1.9.9 forked from zlib 1.2.11 " ; |
32 | |
33 | #ifdef ZLIB_COMPAT |
34 | const char * ZEXPORT zlibVersion(void) |
35 | { |
36 | return ZLIB_VERSION; |
37 | } |
38 | #endif |
39 | |
40 | const char * ZEXPORT zlibng_version(void) |
41 | { |
42 | return ZLIBNG_VERSION; |
43 | } |
44 | |
45 | unsigned long ZEXPORT PREFIX(zlibCompileFlags)(void) |
46 | { |
47 | unsigned long flags; |
48 | |
49 | flags = 0; |
50 | switch ((int)(sizeof(unsigned int))) { |
51 | case 2: break; |
52 | case 4: flags += 1; break; |
53 | case 8: flags += 2; break; |
54 | default: flags += 3; |
55 | } |
56 | switch ((int)(sizeof(unsigned long))) { |
57 | case 2: break; |
58 | case 4: flags += 1 << 2; break; |
59 | case 8: flags += 2 << 2; break; |
60 | default: flags += 3 << 2; |
61 | } |
62 | switch ((int)(sizeof(void *))) { |
63 | case 2: break; |
64 | case 4: flags += 1 << 4; break; |
65 | case 8: flags += 2 << 4; break; |
66 | default: flags += 3 << 4; |
67 | } |
68 | switch ((int)(sizeof(z_off_t))) { |
69 | case 2: break; |
70 | case 4: flags += 1 << 6; break; |
71 | case 8: flags += 2 << 6; break; |
72 | default: flags += 3 << 6; |
73 | } |
74 | #ifdef ZLIB_DEBUG |
75 | flags += 1 << 8; |
76 | #endif |
77 | #ifdef ZLIB_WINAPI |
78 | flags += 1 << 10; |
79 | #endif |
80 | #ifdef DYNAMIC_CRC_TABLE |
81 | flags += 1 << 13; |
82 | #endif |
83 | #ifdef NO_GZCOMPRESS |
84 | flags += 1L << 16; |
85 | #endif |
86 | #ifdef NO_GZIP |
87 | flags += 1L << 17; |
88 | #endif |
89 | #ifdef PKZIP_BUG_WORKAROUND |
90 | flags += 1L << 20; |
91 | #endif |
92 | return flags; |
93 | } |
94 | |
95 | #ifdef ZLIB_DEBUG |
96 | #include <stdlib.h> |
97 | # ifndef verbose |
98 | # define verbose 0 |
99 | # endif |
100 | int ZLIB_INTERNAL z_verbose = verbose; |
101 | |
102 | void ZLIB_INTERNAL z_error (m) |
103 | char *m; |
104 | { |
105 | fprintf(stderr, "%s\n" , m); |
106 | exit(1); |
107 | } |
108 | #endif |
109 | |
110 | /* exported to allow conversion of error code to string for compress() and |
111 | * uncompress() |
112 | */ |
113 | const char * ZEXPORT PREFIX(zError)(int err) |
114 | { |
115 | return ERR_MSG(err); |
116 | } |
117 | |
118 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */ |
119 | |
120 | void ZLIB_INTERNAL *zng_calloc (void *opaque, unsigned items, unsigned size) |
121 | { |
122 | (void)opaque; |
123 | #ifndef UNALIGNED_OK |
124 | return memalign(16, items * size); |
125 | #else |
126 | return sizeof(unsigned int) > 2 ? (void *)malloc(items * size) : |
127 | (void *)calloc(items, size); |
128 | #endif |
129 | } |
130 | |
131 | void ZLIB_INTERNAL zng_cfree (void *opaque, void *ptr) |
132 | { |
133 | (void)opaque; |
134 | free(ptr); |
135 | } |
136 | |
137 | #endif /* MY_ZCALLOC */ |
138 | |