]>
git.saurik.com Git - wxWidgets.git/blob - src/zlib/zutil.c
1 /* zutil.c -- target dependent utility functions for the compression library
2 * Copyright (C) 1995-1998 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
10 struct internal_state
{int dummy
;}; /* for buggy compilers */
13 extern void exit
OF((int));
16 const char *z_errmsg
[10] = {
17 "need dictionary", /* Z_NEED_DICT 2 */
18 "stream end", /* Z_STREAM_END 1 */
20 "file error", /* Z_ERRNO (-1) */
21 "stream error", /* Z_STREAM_ERROR (-2) */
22 "data error", /* Z_DATA_ERROR (-3) */
23 "insufficient memory", /* Z_MEM_ERROR (-4) */
24 "buffer error", /* Z_BUF_ERROR (-5) */
25 "incompatible version",/* Z_VERSION_ERROR (-6) */
29 const char * ZEXPORT
zlibVersion()
39 int z_verbose
= verbose
;
41 #if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */
42 void z_error (char* m
)
48 fprintf(stderr
, "%s\n", m
);
53 /* exported to allow conversion of error code to string for compress() and
56 #if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */
57 const char* ZEXPORT
zError(int err
)
59 const char * ZEXPORT
zError(err
)
69 #if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */
70 void zmemcpy(Bytef
* dest
, Bytef
* source
, Uint len
)
72 void zmemcpy(dest
, source
, len
)
80 *dest
++ = *source
++; /* ??? to be unrolled */
84 #if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */
85 int zmemcmp(Bytef
* s1
, Bytef
* s2
, int len
)
87 int zmemcmp(s1
, s2
, len
)
95 for (j
= 0; j
< len
; j
++) {
96 if (s1
[j
] != s2
[j
]) return 2*(s1
[j
] > s2
[j
])-1;
101 #if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */
102 void zmemzero(Bytef
* dest
, uInt len
)
104 void zmemzero(dest
, len
)
109 if (len
== 0) return;
111 *dest
++ = 0; /* ??? to be unrolled */
112 } while (--len
!= 0);
117 #if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
118 /* Small and medium model in Turbo C are for now limited to near allocation
119 * with reduced MAX_WBITS and MAX_MEM_LEVEL
123 /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
124 * and farmalloc(64K) returns a pointer with an offset of 8, so we
125 * must fix the pointer. Warning: the pointer must be put back to its
126 * original form in order to free it, use zcfree().
132 local
int next_ptr
= 0;
134 typedef struct ptr_table_s
{
139 local ptr_table table
[MAX_PTR
];
140 /* This table is used to remember the original form of pointers
141 * to large buffers (64K). Such pointers are normalized with a zero offset.
142 * Since MSDOS is not a preemptive multitasking OS, this table is not
143 * protected from concurrent access. This hack doesn't work anyway on
144 * a protected system like OS/2. Use Microsoft C instead.
147 voidpf
zcalloc (voidpf opaque
, unsigned items
, unsigned size
)
149 voidpf buf
= opaque
; /* just to make some compilers happy */
150 ulg bsize
= (ulg
)items
*size
;
152 /* If we allocate less than 65520 bytes, we assume that farmalloc
153 * will return a usable pointer which doesn't have to be normalized.
155 if (bsize
< 65520L) {
156 buf
= farmalloc(bsize
);
157 if (*(ush
*)&buf
!= 0) return buf
;
159 buf
= farmalloc(bsize
+ 16L);
161 if (buf
== NULL
|| next_ptr
>= MAX_PTR
) return NULL
;
162 table
[next_ptr
].org_ptr
= buf
;
164 /* Normalize the pointer to seg:0 */
165 *((ush
*)&buf
+1) += ((ush
)((uch
*)buf
-0) + 15) >> 4;
167 table
[next_ptr
++].new_ptr
= buf
;
171 void zcfree (voidpf opaque
, voidpf ptr
)
174 if (*(ush
*)&ptr
!= 0) { /* object < 64K */
178 /* Find the original pointer */
179 for (n
= 0; n
< next_ptr
; n
++) {
180 if (ptr
!= table
[n
].new_ptr
) continue;
182 farfree(table
[n
].org_ptr
);
183 while (++n
< next_ptr
) {
184 table
[n
-1] = table
[n
];
189 ptr
= opaque
; /* just to make some compilers happy */
190 Assert(0, "zcfree: ptr not found");
193 #endif /* __TURBOC__ */
196 #if defined(M_I86) && !defined(__32BIT__)
197 /* Microsoft C in 16-bit mode */
201 #if (!defined(_MSC_VER) || (_MSC_VER < 600))
202 # define _halloc halloc
203 # define _hfree hfree
206 voidpf
zcalloc (voidpf opaque
, unsigned items
, unsigned size
)
208 if (opaque
) opaque
= 0; /* to make compiler happy */
209 return _halloc((long)items
, size
);
212 void zcfree (voidpf opaque
, voidpf ptr
)
214 if (opaque
) opaque
= 0; /* to make compiler happy */
221 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
224 extern voidp calloc
OF((uInt items
, uInt size
));
225 extern void free
OF((voidpf ptr
));
228 #if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */
229 voidpf
zcalloc (voidpf opaque
, unsigned items
, unsigned size
)
231 voidpf
zcalloc (opaque
, items
, size
)
237 if (opaque
) items
+= size
- size
; /* make compiler happy */
238 return (voidpf
)calloc(items
, size
);
241 #if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */
242 void zcfree(voidpf opaque
, voidpf ptr
)
244 void zcfree (opaque
, ptr
)
250 if (opaque
) return; /* make compiler happy */
253 #endif /* MY_ZCALLOC */