00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #include "zutil.h"
00009 
00010 struct internal_state      {int dummy;}; 
00011 
00012 #ifndef STDC
00013 extern void exit OF((int));
00014 #endif
00015 
00016 const char *z_errmsg[10] = {
00017 "need dictionary",     
00018 "stream end",          
00019 "",                    
00020 "file error",          
00021 "stream error",        
00022 "data error",          
00023 "insufficient memory", 
00024 "buffer error",        
00025 "incompatible version",
00026 ""};
00027 
00028 
00029 const char * ZEXPORT zlibVersion()
00030 {
00031     return ZLIB_VERSION;
00032 }
00033 
00034 #ifdef DEBUG
00035 
00036 #  ifndef verbose
00037 #    define verbose 0
00038 #  endif
00039 int z_verbose = verbose;
00040 
00041 void z_error (m)
00042     char *m;
00043 {
00044     fprintf(stderr, "%s\n", m);
00045     exit(1);
00046 }
00047 #endif
00048 
00049 
00050 
00051 
00052 const char * ZEXPORT zError(err)
00053     int err;
00054 {
00055     return ERR_MSG(err);
00056 }
00057 
00058 
00059 #ifndef HAVE_MEMCPY
00060 
00061 void zmemcpy(dest, source, len)
00062     Bytef* dest;
00063     const Bytef* source;
00064     uInt  len;
00065 {
00066     if (len == 0) return;
00067     do {
00068         *dest++ = *source++; 
00069     } while (--len != 0);
00070 }
00071 
00072 int zmemcmp(s1, s2, len)
00073     const Bytef* s1;
00074     const Bytef* s2;
00075     uInt  len;
00076 {
00077     uInt j;
00078 
00079     for (j = 0; j < len; j++) {
00080         if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
00081     }
00082     return 0;
00083 }
00084 
00085 void zmemzero(dest, len)
00086     Bytef* dest;
00087     uInt  len;
00088 {
00089     if (len == 0) return;
00090     do {
00091         *dest++ = 0;  
00092     } while (--len != 0);
00093 }
00094 #endif
00095 
00096 #ifdef __TURBOC__
00097 #if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
00098 
00099 
00100 
00101 #  define MY_ZCALLOC
00102 
00103 
00104 
00105 
00106 
00107 
00108 
00109 #define MAX_PTR 10
00110 
00111 
00112 local int next_ptr = 0;
00113 
00114 typedef struct ptr_table_s {
00115     voidpf org_ptr;
00116     voidpf new_ptr;
00117 } ptr_table;
00118 
00119 local ptr_table table[MAX_PTR];
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
00128 {
00129     voidpf buf = opaque; 
00130     ulg bsize = (ulg)items*size;
00131 
00132     
00133 
00134 
00135     if (bsize < 65520L) {
00136         buf = farmalloc(bsize);
00137         if (*(ush*)&buf != 0) return buf;
00138     } else {
00139         buf = farmalloc(bsize + 16L);
00140     }
00141     if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
00142     table[next_ptr].org_ptr = buf;
00143 
00144     
00145     *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
00146     *(ush*)&buf = 0;
00147     table[next_ptr++].new_ptr = buf;
00148     return buf;
00149 }
00150 
00151 void  zcfree (voidpf opaque, voidpf ptr)
00152 {
00153     int n;
00154     if (*(ush*)&ptr != 0) { 
00155         farfree(ptr);
00156         return;
00157     }
00158     
00159     for (n = 0; n < next_ptr; n++) {
00160         if (ptr != table[n].new_ptr) continue;
00161 
00162         farfree(table[n].org_ptr);
00163         while (++n < next_ptr) {
00164             table[n-1] = table[n];
00165         }
00166         next_ptr--;
00167         return;
00168     }
00169     ptr = opaque; 
00170     Assert(0, "zcfree: ptr not found");
00171 }
00172 #endif
00173 #endif 
00174 
00175 
00176 #if defined(M_I86) && !defined(__32BIT__)
00177 
00178 
00179 #  define MY_ZCALLOC
00180 
00181 #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
00182 #  define _halloc  halloc
00183 #  define _hfree   hfree
00184 #endif
00185 
00186 voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
00187 {
00188     if (opaque) opaque = 0; 
00189     return _halloc((long)items, size);
00190 }
00191 
00192 void  zcfree (voidpf opaque, voidpf ptr)
00193 {
00194     if (opaque) opaque = 0; 
00195     _hfree(ptr);
00196 }
00197 
00198 #endif 
00199 
00200 
00201 #ifndef MY_ZCALLOC 
00202 
00203 #ifndef STDC
00204 extern voidp  calloc OF((uInt items, uInt size));
00205 extern void   free   OF((voidpf ptr));
00206 #endif
00207 
00208 voidpf zcalloc (opaque, items, size)
00209     voidpf opaque;
00210     unsigned items;
00211     unsigned size;
00212 {
00213     if (opaque) items += size - size; 
00214     return (voidpf)calloc(items, size);
00215 }
00216 
00217 void  zcfree (opaque, ptr)
00218     voidpf opaque;
00219     voidpf ptr;
00220 {
00221     free(ptr);
00222     if (opaque) return; 
00223 }
00224 
00225 #endif