/[LeafOK_CVS]/pvpgn-1.7.4/src/zlib/pvpgn_zutil.c
ViewVC logotype

Annotation of /pvpgn-1.7.4/src/zlib/pvpgn_zutil.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (hide annotations) (vendor branch)
Tue Jun 6 03:41:38 2006 UTC (19 years, 9 months ago) by sysadm
Branch: GNU, MAIN
CVS Tags: arelease, HEAD
Changes since 1.1: +0 -0 lines
Content type: text/x-csrc
no message

1 sysadm 1.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     */
5    
6     #include "common/setup_before.h"
7     #include "zlib/pvpgn_zutil.h"
8    
9     struct internal_state {int dummy;}; /* for buggy compilers */
10    
11     #ifndef STDC
12     extern void exit OF((int));
13     #endif
14    
15     const char *pvpgn_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) */
24     "incompatible version",/* Z_VERSION_ERROR (-6) */
25     ""};
26    
27    
28     const char * ZEXPORT pvpgn_zlibVersion()
29     {
30     return ZLIB_VERSION;
31     }
32    
33     #ifdef DEBUG
34    
35     # ifndef verbose
36     # define verbose 0
37     # endif
38     int pvpgn_z_verbose = verbose;
39    
40     void pvpgn_z_error (m)
41     char *m;
42     {
43     fprintf(stderr, "%s\n", m);
44     exit(1);
45     }
46     #endif
47    
48     /* exported to allow conversion of error code to string for compress() and
49     * uncompress()
50     */
51     const char * ZEXPORT pvpgn_zError(err)
52     int err;
53     {
54     return ERR_MSG(err);
55     }
56    
57    
58     #ifndef HAVE_MEMCPY
59    
60     void pvpgn_zmemcpy(dest, source, len)
61     Bytef* dest;
62     const Bytef* source;
63     uInt len;
64     {
65     if (len == 0) return;
66     do {
67     *dest++ = *source++; /* ??? to be unrolled */
68     } while (--len != 0);
69     }
70    
71     int pvpgn_zmemcmp(s1, s2, len)
72     const Bytef* s1;
73     const Bytef* s2;
74     uInt len;
75     {
76     uInt j;
77    
78     for (j = 0; j < len; j++) {
79     if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
80     }
81     return 0;
82     }
83    
84     void pvpgn_zmemzero(dest, len)
85     Bytef* dest;
86     uInt len;
87     {
88     if (len == 0) return;
89     do {
90     *dest++ = 0; /* ??? to be unrolled */
91     } while (--len != 0);
92     }
93     #endif
94    
95     #ifdef __TURBOC__
96     #if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
97     /* Small and medium model in Turbo C are for now limited to near allocation
98     * with reduced MAX_WBITS and MAX_MEM_LEVEL
99     */
100     # define MY_ZCALLOC
101    
102     /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
103     * and farmalloc(64K) returns a pointer with an offset of 8, so we
104     * must fix the pointer. Warning: the pointer must be put back to its
105     * original form in order to free it, use zcfree().
106     */
107    
108     #define MAX_PTR 10
109     /* 10*64K = 640K */
110    
111     local int next_ptr = 0;
112    
113     typedef struct ptr_table_s {
114     voidpf org_ptr;
115     voidpf new_ptr;
116     } ptr_table;
117    
118     local ptr_table table[MAX_PTR];
119     /* This table is used to remember the original form of pointers
120     * to large buffers (64K). Such pointers are normalized with a zero offset.
121     * Since MSDOS is not a preemptive multitasking OS, this table is not
122     * protected from concurrent access. This hack doesn't work anyway on
123     * a protected system like OS/2. Use Microsoft C instead.
124     */
125    
126     voidpf pvpgn_zcalloc (voidpf opaque, unsigned items, unsigned size)
127     {
128     voidpf buf = opaque; /* just to make some compilers happy */
129     ulg bsize = (ulg)items*size;
130    
131     /* If we allocate less than 65520 bytes, we assume that farmalloc
132     * will return a usable pointer which doesn't have to be normalized.
133     */
134     if (bsize < 65520L) {
135     buf = farmalloc(bsize);
136     if (*(ush*)&buf != 0) return buf;
137     } else {
138     buf = farmalloc(bsize + 16L);
139     }
140     if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
141     table[next_ptr].org_ptr = buf;
142    
143     /* Normalize the pointer to seg:0 */
144     *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
145     *(ush*)&buf = 0;
146     table[next_ptr++].new_ptr = buf;
147     return buf;
148     }
149    
150     void pvpgn_zcfree (voidpf opaque, voidpf ptr)
151     {
152     int n;
153     if (*(ush*)&ptr != 0) { /* object < 64K */
154     farfree(ptr);
155     return;
156     }
157     /* Find the original pointer */
158     for (n = 0; n < next_ptr; n++) {
159     if (ptr != table[n].new_ptr) continue;
160    
161     farfree(table[n].org_ptr);
162     while (++n < next_ptr) {
163     table[n-1] = table[n];
164     }
165     next_ptr--;
166     return;
167     }
168     ptr = opaque; /* just to make some compilers happy */
169     Assert(0, "zcfree: ptr not found");
170     }
171     #endif
172     #endif /* __TURBOC__ */
173    
174    
175     #if defined(M_I86) && !defined(__32BIT__)
176     /* Microsoft C in 16-bit mode */
177    
178     # define MY_ZCALLOC
179    
180     #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
181     # define _halloc halloc
182     # define _hfree hfree
183     #endif
184    
185     voidpf pvpgn_zcalloc (voidpf opaque, unsigned items, unsigned size)
186     {
187     if (opaque) opaque = 0; /* to make compiler happy */
188     return _halloc((long)items, size);
189     }
190    
191     void pvpgn_zcfree (voidpf opaque, voidpf ptr)
192     {
193     if (opaque) opaque = 0; /* to make compiler happy */
194     _hfree(ptr);
195     }
196    
197     #endif /* MSC */
198    
199    
200     #ifndef MY_ZCALLOC /* Any system without a special alloc function */
201    
202     #ifndef STDC
203     extern voidp calloc OF((uInt items, uInt size));
204     extern void free OF((voidpf ptr));
205     #endif
206    
207     voidpf pvpgn_zcalloc (opaque, items, size)
208     voidpf opaque;
209     unsigned items;
210     unsigned size;
211     {
212     if (opaque) items += size - size; /* make compiler happy */
213     return (voidpf)calloc(items, size);
214     }
215    
216     void pvpgn_zcfree (opaque, ptr)
217     voidpf opaque;
218     voidpf ptr;
219     {
220     free(ptr);
221     if (opaque) return; /* make compiler happy */
222     }
223    
224     #endif /* MY_ZCALLOC */

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1