1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/compressionlibs/ziplib/test/oldezlib/Zlib/zutil.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,210 @@
1.4 +/* zutil.c -- target dependent utility functions for the compression library
1.5 + * Copyright (C) 1995-1998 Jean-loup Gailly.
1.6 + * For conditions of distribution and use, see copyright notice in zlib.h
1.7 + */
1.8 +
1.9 +/* @(#) $Id$ */
1.10 +
1.11 +#include "zutil.h"
1.12 +
1.13 +struct internal_state {int dummy;}; /* for buggy compilers */
1.14 +
1.15 +#ifndef STDC
1.16 +extern void exit OF((int));
1.17 +#endif
1.18 +
1.19 +const char *z_errmsg[10] = {
1.20 +"need dictionary", /* Z_NEED_DICT 2 */
1.21 +"stream end", /* Z_STREAM_END 1 */
1.22 +"", /* Z_OK 0 */
1.23 +"file error", /* Z_ERRNO (-1) */
1.24 +"stream error", /* Z_STREAM_ERROR (-2) */
1.25 +"data error", /* Z_DATA_ERROR (-3) */
1.26 +"insufficient memory", /* Z_MEM_ERROR (-4) */
1.27 +"buffer error", /* Z_BUF_ERROR (-5) */
1.28 +"incompatible version",/* Z_VERSION_ERROR (-6) */
1.29 +""};
1.30 +
1.31 +
1.32 +const char * ZEXPORT zlibVersion()
1.33 +{
1.34 + return ZLIB_VERSION;
1.35 +}
1.36 +
1.37 +#ifdef DEBUG
1.38 +
1.39 +# ifndef verbose
1.40 +# define verbose 0
1.41 +# endif
1.42 +int z_verbose = verbose;
1.43 +
1.44 +void z_error (char *m)
1.45 +{
1.46 + fprintf(stderr, "%s\n", m);
1.47 + exit(1);
1.48 +}
1.49 +#endif
1.50 +
1.51 +/* exported to allow conversion of error code to string for compress() and
1.52 + * uncompress()
1.53 + */
1.54 +const char * ZEXPORT zError(int err)
1.55 +{
1.56 + return ERR_MSG(err);
1.57 +}
1.58 +
1.59 +
1.60 +#ifndef HAVE_MEMCPY
1.61 +
1.62 +void zmemcpy(Bytef* dest, const Bytef* source, uInt len)
1.63 +{
1.64 + if (len == 0) return;
1.65 + do {
1.66 + *dest++ = *source++; /* ??? to be unrolled */
1.67 + } while (--len != 0);
1.68 +}
1.69 +
1.70 +int zmemcmp(const Bytef* s1, const Bytef* s2, uInt len)
1.71 +{
1.72 + uInt j;
1.73 +
1.74 + for (j = 0; j < len; j++) {
1.75 + if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
1.76 + }
1.77 + return 0;
1.78 +}
1.79 +
1.80 +void zmemzero(Bytef* dest, uInt len)
1.81 +{
1.82 + if (len == 0) return;
1.83 + do {
1.84 + *dest++ = 0; /* ??? to be unrolled */
1.85 + } while (--len != 0);
1.86 +}
1.87 +#endif
1.88 +
1.89 +#ifdef __TURBOC__
1.90 +#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
1.91 +/* Small and medium model in Turbo C are for now limited to near allocation
1.92 + * with reduced MAX_WBITS and MAX_MEM_LEVEL
1.93 + */
1.94 +# define MY_ZCALLOC
1.95 +
1.96 +/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
1.97 + * and farmalloc(64K) returns a pointer with an offset of 8, so we
1.98 + * must fix the pointer. Warning: the pointer must be put back to its
1.99 + * original form in order to free it, use zcfree().
1.100 + */
1.101 +
1.102 +#define MAX_PTR 10
1.103 +/* 10*64K = 640K */
1.104 +
1.105 +local int next_ptr = 0;
1.106 +
1.107 +typedef struct ptr_table_s {
1.108 + voidpf org_ptr;
1.109 + voidpf new_ptr;
1.110 +} ptr_table;
1.111 +
1.112 +local ptr_table table[MAX_PTR];
1.113 +/* This table is used to remember the original form of pointers
1.114 + * to large buffers (64K). Such pointers are normalized with a zero offset.
1.115 + * Since MSDOS is not a preemptive multitasking OS, this table is not
1.116 + * protected from concurrent access. This hack doesn't work anyway on
1.117 + * a protected system like OS/2. Use Microsoft C instead.
1.118 + */
1.119 +
1.120 +voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
1.121 +{
1.122 + voidpf buf = opaque; /* just to make some compilers happy */
1.123 + ulg bsize = (ulg)items*size;
1.124 +
1.125 + /* If we allocate less than 65520 bytes, we assume that farmalloc
1.126 + * will return a usable pointer which doesn't have to be normalized.
1.127 + */
1.128 + if (bsize < 65520L) {
1.129 + buf = farmalloc(bsize);
1.130 + if (*(ush*)&buf != 0) return buf;
1.131 + } else {
1.132 + buf = farmalloc(bsize + 16L);
1.133 + }
1.134 + if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
1.135 + table[next_ptr].org_ptr = buf;
1.136 +
1.137 + /* Normalize the pointer to seg:0 */
1.138 + *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
1.139 + *(ush*)&buf = 0;
1.140 + table[next_ptr++].new_ptr = buf;
1.141 + return buf;
1.142 +}
1.143 +
1.144 +void zcfree (voidpf opaque, voidpf ptr)
1.145 +{
1.146 + int n;
1.147 + if (*(ush*)&ptr != 0) { /* object < 64K */
1.148 + farfree(ptr);
1.149 + return;
1.150 + }
1.151 + /* Find the original pointer */
1.152 + for (n = 0; n < next_ptr; n++) {
1.153 + if (ptr != table[n].new_ptr) continue;
1.154 +
1.155 + farfree(table[n].org_ptr);
1.156 + while (++n < next_ptr) {
1.157 + table[n-1] = table[n];
1.158 + }
1.159 + next_ptr--;
1.160 + return;
1.161 + }
1.162 + ptr = opaque; /* just to make some compilers happy */
1.163 + Assert(0, "zcfree: ptr not found");
1.164 +}
1.165 +#endif
1.166 +#endif /* __TURBOC__ */
1.167 +
1.168 +
1.169 +#if defined(M_I86) && !defined(__32BIT__)
1.170 +/* Microsoft C in 16-bit mode */
1.171 +
1.172 +# define MY_ZCALLOC
1.173 +
1.174 +#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
1.175 +# define _halloc halloc
1.176 +# define _hfree hfree
1.177 +#endif
1.178 +
1.179 +voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
1.180 +{
1.181 + if (opaque) opaque = 0; /* to make compiler happy */
1.182 + return _halloc((long)items, size);
1.183 +}
1.184 +
1.185 +void zcfree (voidpf opaque, voidpf ptr)
1.186 +{
1.187 + if (opaque) opaque = 0; /* to make compiler happy */
1.188 + _hfree(ptr);
1.189 +}
1.190 +
1.191 +#endif /* MSC */
1.192 +
1.193 +
1.194 +#ifndef MY_ZCALLOC /* Any system without a special alloc function */
1.195 +
1.196 +#ifndef STDC
1.197 +extern voidp calloc OF((uInt items, uInt size));
1.198 +extern void free OF((voidpf ptr));
1.199 +#endif
1.200 +
1.201 +voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
1.202 +{
1.203 + if (opaque) items += size - size; /* make compiler happy */
1.204 + return (voidpf)calloc(items, size);
1.205 +}
1.206 +
1.207 +void zcfree (voidpf opaque,voidpf ptr)
1.208 +{
1.209 + free(ptr);
1.210 + if (opaque) return; /* make compiler happy */
1.211 +}
1.212 +
1.213 +#endif /* MY_ZCALLOC */