diff options
Diffstat (limited to 'dep/src/zlib/zutil.c')
-rw-r--r-- | dep/src/zlib/zutil.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/dep/src/zlib/zutil.c b/dep/src/zlib/zutil.c index 09b456e54e4..d55f5948a37 100644 --- a/dep/src/zlib/zutil.c +++ b/dep/src/zlib/zutil.c @@ -2,11 +2,15 @@ * Copyright (C) 1995-2005 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ + /* @(#) $Id$ */ + #include "zutil.h" + #ifndef NO_DUMMY_DECL struct internal_state {int dummy;}; /* for buggy compilers */ #endif + const char * const z_errmsg[10] = { "need dictionary", /* Z_NEED_DICT 2 */ "stream end", /* Z_STREAM_END 1 */ @@ -19,13 +23,16 @@ const char * const z_errmsg[10] = { "incompatible version",/* Z_VERSION_ERROR (-6) */ ""}; + const char * ZEXPORT zlibVersion() { return ZLIB_VERSION; } + uLong ZEXPORT zlibCompileFlags() { uLong flags; + flags = 0; switch (sizeof(uInt)) { case 2: break; @@ -104,11 +111,14 @@ uLong ZEXPORT zlibCompileFlags() #endif return flags; } + #ifdef DEBUG + # ifndef verbose # define verbose 0 # endif int z_verbose = verbose; + void z_error (m) char *m; { @@ -116,6 +126,7 @@ void z_error (m) exit(1); } #endif + /* exported to allow conversion of error code to string for compress() and * uncompress() */ @@ -124,6 +135,7 @@ const char * ZEXPORT zError(err) { return ERR_MSG(err); } + #if defined(_WIN32_WCE) /* The Microsoft C Run-Time Library for Windows CE doesn't have * errno. We define it as a global variable to simplify porting. @@ -131,7 +143,9 @@ const char * ZEXPORT zError(err) */ int errno = 0; #endif + #ifndef HAVE_MEMCPY + void zmemcpy(dest, source, len) Bytef* dest; const Bytef* source; @@ -142,17 +156,20 @@ void zmemcpy(dest, source, len) *dest++ = *source++; /* ??? to be unrolled */ } while (--len != 0); } + int zmemcmp(s1, s2, len) const Bytef* s1; const Bytef* s2; uInt len; { uInt j; + for (j = 0; j < len; j++) { if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; } return 0; } + void zmemzero(dest, len) Bytef* dest; uInt len; @@ -164,22 +181,30 @@ void zmemzero(dest, len) } #endif + #ifdef SYS16BIT + #ifdef __TURBOC__ /* Turbo C in 16-bit mode */ + # define MY_ZCALLOC + /* Turbo C malloc() does not allow dynamic allocation of 64K bytes * and farmalloc(64K) returns a pointer with an offset of 8, so we * must fix the pointer. Warning: the pointer must be put back to its * original form in order to free it, use zcfree(). */ + #define MAX_PTR 10 /* 10*64K = 640K */ + local int next_ptr = 0; + typedef struct ptr_table_s { voidpf org_ptr; voidpf new_ptr; } ptr_table; + local ptr_table table[MAX_PTR]; /* This table is used to remember the original form of pointers * to large buffers (64K). Such pointers are normalized with a zero offset. @@ -187,10 +212,12 @@ local ptr_table table[MAX_PTR]; * protected from concurrent access. This hack doesn't work anyway on * a protected system like OS/2. Use Microsoft C instead. */ + voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) { voidpf buf = opaque; /* just to make some compilers happy */ ulg bsize = (ulg)items*size; + /* If we allocate less than 65520 bytes, we assume that farmalloc * will return a usable pointer which doesn't have to be normalized. */ @@ -202,12 +229,14 @@ voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) } if (buf == NULL || next_ptr >= MAX_PTR) return NULL; table[next_ptr].org_ptr = buf; + /* Normalize the pointer to seg:0 */ *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; *(ush*)&buf = 0; table[next_ptr++].new_ptr = buf; return buf; } + void zcfree (voidpf opaque, voidpf ptr) { int n; @@ -218,6 +247,7 @@ void zcfree (voidpf opaque, voidpf ptr) /* Find the original pointer */ for (n = 0; n < next_ptr; n++) { if (ptr != table[n].new_ptr) continue; + farfree(table[n].org_ptr); while (++n < next_ptr) { table[n-1] = table[n]; @@ -228,34 +258,45 @@ void zcfree (voidpf opaque, voidpf ptr) ptr = opaque; /* just to make some compilers happy */ Assert(0, "zcfree: ptr not found"); } + #endif /* __TURBOC__ */ + #ifdef M_I86 /* Microsoft C in 16-bit mode */ + # define MY_ZCALLOC + #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) # define _halloc halloc # define _hfree hfree #endif + voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) { if (opaque) opaque = 0; /* to make compiler happy */ return _halloc((long)items, size); } + void zcfree (voidpf opaque, voidpf ptr) { if (opaque) opaque = 0; /* to make compiler happy */ _hfree(ptr); } + #endif /* M_I86 */ + #endif /* SYS16BIT */ + #ifndef MY_ZCALLOC /* Any system without a special alloc function */ + #ifndef STDC extern voidp malloc OF((uInt size)); extern voidp calloc OF((uInt items, uInt size)); extern void free OF((voidpf ptr)); #endif + voidpf zcalloc (opaque, items, size) voidpf opaque; unsigned items; @@ -265,6 +306,7 @@ voidpf zcalloc (opaque, items, size) return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : (voidpf)calloc(items, size); } + void zcfree (opaque, ptr) voidpf opaque; voidpf ptr; @@ -272,4 +314,5 @@ void zcfree (opaque, ptr) free(ptr); if (opaque) return; /* make compiler happy */ } + #endif /* MY_ZCALLOC */ |