source: rtems/cpukit/zlib/zutil.c @ 6ac6a5c8

5
Last change on this file since 6ac6a5c8 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/* zutil.c -- target dependent utility functions for the compression library
2 * Copyright (C) 1995-2005, 2010 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "zutil.h"
7
8#ifndef NO_DUMMY_DECL
9struct internal_state      {int dummy;}; /* for buggy compilers */
10#endif
11
12const char * const z_errmsg[10] = {
13"need dictionary",     /* Z_NEED_DICT       2  */
14"stream end",          /* Z_STREAM_END      1  */
15"",                    /* Z_OK              0  */
16"file error",          /* Z_ERRNO         (-1) */
17"stream error",        /* Z_STREAM_ERROR  (-2) */
18"data error",          /* Z_DATA_ERROR    (-3) */
19"insufficient memory", /* Z_MEM_ERROR     (-4) */
20"buffer error",        /* Z_BUF_ERROR     (-5) */
21"incompatible version",/* Z_VERSION_ERROR (-6) */
22""};
23
24
25const char * ZEXPORT zlibVersion()
26{
27    return ZLIB_VERSION;
28}
29
30uLong ZEXPORT zlibCompileFlags()
31{
32    uLong flags;
33
34    flags = 0;
35    switch ((int)(sizeof(uInt))) {
36    case 2:     break;
37    case 4:     flags += 1;     break;
38    case 8:     flags += 2;     break;
39    default:    flags += 3;
40    }
41    switch ((int)(sizeof(uLong))) {
42    case 2:     break;
43    case 4:     flags += 1 << 2;        break;
44    case 8:     flags += 2 << 2;        break;
45    default:    flags += 3 << 2;
46    }
47    switch ((int)(sizeof(voidpf))) {
48    case 2:     break;
49    case 4:     flags += 1 << 4;        break;
50    case 8:     flags += 2 << 4;        break;
51    default:    flags += 3 << 4;
52    }
53    switch ((int)(sizeof(z_off_t))) {
54    case 2:     break;
55    case 4:     flags += 1 << 6;        break;
56    case 8:     flags += 2 << 6;        break;
57    default:    flags += 3 << 6;
58    }
59#ifdef DEBUG
60    flags += 1 << 8;
61#endif
62#if defined(ASMV) || defined(ASMINF)
63    flags += 1 << 9;
64#endif
65#ifdef ZLIB_WINAPI
66    flags += 1 << 10;
67#endif
68#ifdef BUILDFIXED
69    flags += 1 << 12;
70#endif
71#ifdef DYNAMIC_CRC_TABLE
72    flags += 1 << 13;
73#endif
74#ifdef NO_GZCOMPRESS
75    flags += 1L << 16;
76#endif
77#ifdef NO_GZIP
78    flags += 1L << 17;
79#endif
80#ifdef PKZIP_BUG_WORKAROUND
81    flags += 1L << 20;
82#endif
83#ifdef FASTEST
84    flags += 1L << 21;
85#endif
86#ifdef STDC
87#  ifdef NO_vsnprintf
88        flags += 1L << 25;
89#    ifdef HAS_vsprintf_void
90        flags += 1L << 26;
91#    endif
92#  else
93#    ifdef HAS_vsnprintf_void
94        flags += 1L << 26;
95#    endif
96#  endif
97#else
98        flags += 1L << 24;
99#  ifdef NO_snprintf
100        flags += 1L << 25;
101#    ifdef HAS_sprintf_void
102        flags += 1L << 26;
103#    endif
104#  else
105#    ifdef HAS_snprintf_void
106        flags += 1L << 26;
107#    endif
108#  endif
109#endif
110    return flags;
111}
112
113#ifdef DEBUG
114
115#  ifndef verbose
116#    define verbose 0
117#  endif
118int ZLIB_INTERNAL z_verbose = verbose;
119
120void ZLIB_INTERNAL z_error (m)
121    char *m;
122{
123    fprintf(stderr, "%s\n", m);
124    exit(1);
125}
126#endif
127
128/* exported to allow conversion of error code to string for compress() and
129 * uncompress()
130 */
131const char * ZEXPORT zError(err)
132    int err;
133{
134    return ERR_MSG(err);
135}
136
137#if defined(_WIN32_WCE)
138    /* The Microsoft C Run-Time Library for Windows CE doesn't have
139     * errno.  We define it as a global variable to simplify porting.
140     * Its value is always 0 and should not be used.
141     */
142    int errno = 0;
143#endif
144
145#ifndef HAVE_MEMCPY
146
147void ZLIB_INTERNAL zmemcpy(dest, source, len)
148    Bytef* dest;
149    const Bytef* source;
150    uInt  len;
151{
152    if (len == 0) return;
153    do {
154        *dest++ = *source++; /* ??? to be unrolled */
155    } while (--len != 0);
156}
157
158int ZLIB_INTERNAL zmemcmp(s1, s2, len)
159    const Bytef* s1;
160    const Bytef* s2;
161    uInt  len;
162{
163    uInt j;
164
165    for (j = 0; j < len; j++) {
166        if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
167    }
168    return 0;
169}
170
171void ZLIB_INTERNAL zmemzero(dest, len)
172    Bytef* dest;
173    uInt  len;
174{
175    if (len == 0) return;
176    do {
177        *dest++ = 0;  /* ??? to be unrolled */
178    } while (--len != 0);
179}
180#endif
181
182
183#ifdef SYS16BIT
184
185#ifdef __TURBOC__
186/* Turbo C in 16-bit mode */
187
188#  define MY_ZCALLOC
189
190/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
191 * and farmalloc(64K) returns a pointer with an offset of 8, so we
192 * must fix the pointer. Warning: the pointer must be put back to its
193 * original form in order to free it, use zcfree().
194 */
195
196#define MAX_PTR 10
197/* 10*64K = 640K */
198
199local int next_ptr = 0;
200
201typedef struct ptr_table_s {
202    voidpf org_ptr;
203    voidpf new_ptr;
204} ptr_table;
205
206local ptr_table table[MAX_PTR];
207/* This table is used to remember the original form of pointers
208 * to large buffers (64K). Such pointers are normalized with a zero offset.
209 * Since MSDOS is not a preemptive multitasking OS, this table is not
210 * protected from concurrent access. This hack doesn't work anyway on
211 * a protected system like OS/2. Use Microsoft C instead.
212 */
213
214voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
215{
216    voidpf buf = opaque; /* just to make some compilers happy */
217    ulg bsize = (ulg)items*size;
218
219    /* If we allocate less than 65520 bytes, we assume that farmalloc
220     * will return a usable pointer which doesn't have to be normalized.
221     */
222    if (bsize < 65520L) {
223        buf = farmalloc(bsize);
224        if (*(ush*)&buf != 0) return buf;
225    } else {
226        buf = farmalloc(bsize + 16L);
227    }
228    if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
229    table[next_ptr].org_ptr = buf;
230
231    /* Normalize the pointer to seg:0 */
232    *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
233    *(ush*)&buf = 0;
234    table[next_ptr++].new_ptr = buf;
235    return buf;
236}
237
238void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
239{
240    int n;
241    if (*(ush*)&ptr != 0) { /* object < 64K */
242        farfree(ptr);
243        return;
244    }
245    /* Find the original pointer */
246    for (n = 0; n < next_ptr; n++) {
247        if (ptr != table[n].new_ptr) continue;
248
249        farfree(table[n].org_ptr);
250        while (++n < next_ptr) {
251            table[n-1] = table[n];
252        }
253        next_ptr--;
254        return;
255    }
256    ptr = opaque; /* just to make some compilers happy */
257    Assert(0, "zcfree: ptr not found");
258}
259
260#endif /* __TURBOC__ */
261
262
263#ifdef M_I86
264/* Microsoft C in 16-bit mode */
265
266#  define MY_ZCALLOC
267
268#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
269#  define _halloc  halloc
270#  define _hfree   hfree
271#endif
272
273voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
274{
275    if (opaque) opaque = 0; /* to make compiler happy */
276    return _halloc((long)items, size);
277}
278
279void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
280{
281    if (opaque) opaque = 0; /* to make compiler happy */
282    _hfree(ptr);
283}
284
285#endif /* M_I86 */
286
287#endif /* SYS16BIT */
288
289
290#ifndef MY_ZCALLOC /* Any system without a special alloc function */
291
292#ifndef STDC
293extern voidp  malloc OF((uInt size));
294extern voidp  calloc OF((uInt items, uInt size));
295extern void   free   OF((voidpf ptr));
296#endif
297
298voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
299    voidpf opaque;
300    unsigned items;
301    unsigned size;
302{
303    if (opaque) items += size - size; /* make compiler happy */
304    return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
305                              (voidpf)calloc(items, size);
306}
307
308void ZLIB_INTERNAL zcfree (opaque, ptr)
309    voidpf opaque;
310    voidpf ptr;
311{
312    free(ptr);
313    if (opaque) return; /* make compiler happy */
314}
315
316#endif /* MY_ZCALLOC */
Note: See TracBrowser for help on using the repository browser.