Disabling auto-refresh of game list by default, as it is causing bugs sometimes
[open-ps2-loader.git] / thirdparty / freetype-2.3.12 / src / gzip / zutil.c
blob7ad0c1f81bb48b0d97ecf0d5756923aa183fa42a
1 /* zutil.c -- target dependent utility functions for the compression library
2 * Copyright (C) 1995-2002 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
6 /* @(#) $Id$ */
8 #include "zutil.h"
10 #ifndef STDC
11 extern void exit OF((int));
12 #endif
15 #ifndef HAVE_MEMCPY
17 void zmemcpy(dest, source, len)
18 Bytef* dest;
19 const Bytef* source;
20 uInt len;
22 if (len == 0) return;
23 do {
24 *dest++ = *source++; /* ??? to be unrolled */
25 } while (--len != 0);
28 int zmemcmp(s1, s2, len)
29 const Bytef* s1;
30 const Bytef* s2;
31 uInt len;
33 uInt j;
35 for (j = 0; j < len; j++) {
36 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
38 return 0;
41 void zmemzero(dest, len)
42 Bytef* dest;
43 uInt len;
45 if (len == 0) return;
46 do {
47 *dest++ = 0; /* ??? to be unrolled */
48 } while (--len != 0);
50 #endif
52 #if defined( MSDOS ) && defined( __TURBOC__ ) && !defined( MY_ZCALLOC )
53 #if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
54 /* Small and medium model in Turbo C are for now limited to near allocation
55 * with reduced MAX_WBITS and MAX_MEM_LEVEL
57 # define MY_ZCALLOC
59 /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
60 * and farmalloc(64K) returns a pointer with an offset of 8, so we
61 * must fix the pointer. Warning: the pointer must be put back to its
62 * original form in order to free it, use zcfree().
65 #define MAX_PTR 10
66 /* 10*64K = 640K */
68 local int next_ptr = 0;
70 typedef struct ptr_table_s {
71 voidpf org_ptr;
72 voidpf new_ptr;
73 } ptr_table;
75 local ptr_table table[MAX_PTR];
76 /* This table is used to remember the original form of pointers
77 * to large buffers (64K). Such pointers are normalized with a zero offset.
78 * Since MSDOS is not a preemptive multitasking OS, this table is not
79 * protected from concurrent access. This hack doesn't work anyway on
80 * a protected system like OS/2. Use Microsoft C instead.
83 voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
85 voidpf buf = opaque; /* just to make some compilers happy */
86 ulg bsize = (ulg)items*size;
88 /* If we allocate less than 65520 bytes, we assume that farmalloc
89 * will return a usable pointer which doesn't have to be normalized.
91 if (bsize < 65520L) {
92 buf = farmalloc(bsize);
93 if (*(ush*)&buf != 0) return buf;
94 } else {
95 buf = farmalloc(bsize + 16L);
97 if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
98 table[next_ptr].org_ptr = buf;
100 /* Normalize the pointer to seg:0 */
101 *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
102 *(ush*)&buf = 0;
103 table[next_ptr++].new_ptr = buf;
104 return buf;
107 void zcfree (voidpf opaque, voidpf ptr)
109 int n;
110 if (*(ush*)&ptr != 0) { /* object < 64K */
111 farfree(ptr);
112 return;
114 /* Find the original pointer */
115 for (n = 0; n < next_ptr; n++) {
116 if (ptr != table[n].new_ptr) continue;
118 farfree(table[n].org_ptr);
119 while (++n < next_ptr) {
120 table[n-1] = table[n];
122 next_ptr--;
123 return;
125 ptr = opaque; /* just to make some compilers happy */
126 Assert(0, "zcfree: ptr not found");
128 #endif
129 #endif /* MSDOS && __TURBOC__ */
132 #if defined(M_I86) && !defined(__32BIT__) && !defined( MY_ZCALLOC )
133 /* Microsoft C in 16-bit mode */
135 # define MY_ZCALLOC
137 #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
138 # define _halloc halloc
139 # define _hfree hfree
140 #endif
142 voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
144 if (opaque) opaque = 0; /* to make compiler happy */
145 return _halloc((long)items, size);
148 void zcfree (voidpf opaque, voidpf ptr)
150 if (opaque) opaque = 0; /* to make compiler happy */
151 _hfree(ptr);
154 #endif /* MSC */
157 #ifndef MY_ZCALLOC /* Any system without a special alloc function */
159 #ifndef STDC
160 extern voidp ft_scalloc OF((uInt items, uInt size));
161 extern void ft_sfree OF((voidpf ptr));
162 #endif
164 voidpf zcalloc (opaque, items, size)
165 voidpf opaque;
166 unsigned items;
167 unsigned size;
169 if (opaque) items += size - size; /* make compiler happy */
170 return (voidpf)ft_scalloc(items, size);
173 void zcfree (opaque, ptr)
174 voidpf opaque;
175 voidpf ptr;
177 ft_sfree(ptr);
178 if (opaque) return; /* make compiler happy */
181 #endif /* MY_ZCALLOC */