Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenzutil.c
Go to the documentation of this file.
00001 /* zutil.c -- target dependent utility functions for the compression library 00002 * Copyright (C) 1995-2002 Jean-loup Gailly. 00003 * For conditions of distribution and use, see copyright notice in zlib.h 00004 */ 00005 00006 /* @(#) $Id$ */ 00007 00008 #include "zutil.h" 00009 00010 #ifndef STDC 00011 extern void exit OF((int)); 00012 #endif 00013 00014 00015 #ifndef HAVE_MEMCPY 00016 00017 void zmemcpy(dest, source, len) 00018 Bytef* dest; 00019 const Bytef* source; 00020 uInt len; 00021 { 00022 if (len == 0) return; 00023 do { 00024 *dest++ = *source++; /* ??? to be unrolled */ 00025 } while (--len != 0); 00026 } 00027 00028 int zmemcmp(s1, s2, len) 00029 const Bytef* s1; 00030 const Bytef* s2; 00031 uInt len; 00032 { 00033 uInt j; 00034 00035 for (j = 0; j < len; j++) { 00036 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; 00037 } 00038 return 0; 00039 } 00040 00041 void zmemzero(dest, len) 00042 Bytef* dest; 00043 uInt len; 00044 { 00045 if (len == 0) return; 00046 do { 00047 *dest++ = 0; /* ??? to be unrolled */ 00048 } while (--len != 0); 00049 } 00050 #endif 00051 00052 #if defined( MSDOS ) && defined( __TURBOC__ ) && !defined( MY_ZCALLOC ) 00053 #if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__) 00054 /* Small and medium model in Turbo C are for now limited to near allocation 00055 * with reduced MAX_WBITS and MAX_MEM_LEVEL 00056 */ 00057 # define MY_ZCALLOC 00058 00059 /* Turbo C malloc() does not allow dynamic allocation of 64K bytes 00060 * and farmalloc(64K) returns a pointer with an offset of 8, so we 00061 * must fix the pointer. Warning: the pointer must be put back to its 00062 * original form in order to free it, use zcfree(). 00063 */ 00064 00065 #define MAX_PTR 10 00066 /* 10*64K = 640K */ 00067 00068 local int next_ptr = 0; 00069 00070 typedef struct ptr_table_s { 00071 voidpf org_ptr; 00072 voidpf new_ptr; 00073 } ptr_table; 00074 00075 local ptr_table table[MAX_PTR]; 00076 /* This table is used to remember the original form of pointers 00077 * to large buffers (64K). Such pointers are normalized with a zero offset. 00078 * Since MSDOS is not a preemptive multitasking OS, this table is not 00079 * protected from concurrent access. This hack doesn't work anyway on 00080 * a protected system like OS/2. Use Microsoft C instead. 00081 */ 00082 00083 voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 00084 { 00085 voidpf buf = opaque; /* just to make some compilers happy */ 00086 ulg bsize = (ulg)items*size; 00087 00088 /* If we allocate less than 65520 bytes, we assume that farmalloc 00089 * will return a usable pointer which doesn't have to be normalized. 00090 */ 00091 if (bsize < 65520L) { 00092 buf = farmalloc(bsize); 00093 if (*(ush*)&buf != 0) return buf; 00094 } else { 00095 buf = farmalloc(bsize + 16L); 00096 } 00097 if (buf == NULL || next_ptr >= MAX_PTR) return NULL; 00098 table[next_ptr].org_ptr = buf; 00099 00100 /* Normalize the pointer to seg:0 */ 00101 *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; 00102 *(ush*)&buf = 0; 00103 table[next_ptr++].new_ptr = buf; 00104 return buf; 00105 } 00106 00107 void zcfree (voidpf opaque, voidpf ptr) 00108 { 00109 int n; 00110 if (*(ush*)&ptr != 0) { /* object < 64K */ 00111 farfree(ptr); 00112 return; 00113 } 00114 /* Find the original pointer */ 00115 for (n = 0; n < next_ptr; n++) { 00116 if (ptr != table[n].new_ptr) continue; 00117 00118 farfree(table[n].org_ptr); 00119 while (++n < next_ptr) { 00120 table[n-1] = table[n]; 00121 } 00122 next_ptr--; 00123 return; 00124 } 00125 ptr = opaque; /* just to make some compilers happy */ 00126 Assert(0, "zcfree: ptr not found"); 00127 } 00128 #endif 00129 #endif /* MSDOS && __TURBOC__ */ 00130 00131 00132 #if defined(M_I86) && !defined(__32BIT__) && !defined( MY_ZCALLOC ) 00133 /* Microsoft C in 16-bit mode */ 00134 00135 # define MY_ZCALLOC 00136 00137 #if (!defined(_MSC_VER) || (_MSC_VER <= 600)) 00138 # define _halloc halloc 00139 # define _hfree hfree 00140 #endif 00141 00142 voidpf zcalloc (voidpf opaque, unsigned items, unsigned size) 00143 { 00144 if (opaque) opaque = 0; /* to make compiler happy */ 00145 return _halloc((long)items, size); 00146 } 00147 00148 void zcfree (voidpf opaque, voidpf ptr) 00149 { 00150 if (opaque) opaque = 0; /* to make compiler happy */ 00151 _hfree(ptr); 00152 } 00153 00154 #endif /* MSC */ 00155 00156 00157 #ifndef MY_ZCALLOC /* Any system without a special alloc function */ 00158 00159 #ifndef STDC 00160 extern voidp ft_scalloc OF((uInt items, uInt size)); 00161 extern void ft_sfree OF((voidpf ptr)); 00162 #endif 00163 00164 voidpf zcalloc (opaque, items, size) 00165 voidpf opaque; 00166 unsigned items; 00167 unsigned size; 00168 { 00169 if (opaque) items += size - size; /* make compiler happy */ 00170 return (voidpf)ft_scalloc(items, size); 00171 } 00172 00173 void zcfree (opaque, ptr) 00174 voidpf opaque; 00175 voidpf ptr; 00176 { 00177 ft_sfree(ptr); 00178 if (opaque) return; /* make compiler happy */ 00179 } 00180 00181 #endif /* MY_ZCALLOC */ Generated on Sat May 26 2012 04:32:45 for ReactOS by
1.7.6.1
|