ReactOS 0.4.15-dev-7934-g1dc8d80
zutil.c
Go to the documentation of this file.
1/* zutil.c -- target dependent utility functions for the compression library
2 * Copyright (C) 1995-2002 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6/* @(#) $Id$ */
7
8#include "zutil.h"
9
10#ifndef STDC
11extern void exit OF((int));
12#endif
13
14
15#ifndef HAVE_MEMCPY
16
18 Bytef* dest;
19 const Bytef* source;
20 uInt len;
21{
22 if (len == 0) return;
23 do {
24 *dest++ = *source++; /* ??? to be unrolled */
25 } while (--len != 0);
26}
27
29 const Bytef* s1;
30 const Bytef* s2;
31 uInt len;
32{
33 uInt j;
34
35 for (j = 0; j < len; j++) {
36 if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
37 }
38 return 0;
39}
40
42 Bytef* dest;
43 uInt len;
44{
45 if (len == 0) return;
46 do {
47 *dest++ = 0; /* ??? to be unrolled */
48 } while (--len != 0);
49}
50#endif
51
52#if defined( MSDOS ) && defined( __TURBOC__ ) && !defined( MY_ZCALLOC )
53#if (defined( __BORLANDC__) || !defined(SMALL_MEDIUM)) && !defined(__32BIT__)
54/* Small and medium model in Turbo C are for now limited to near allocation
55 * with reduced MAX_WBITS and MAX_MEM_LEVEL
56 */
57# define MY_ZCALLOC
58
59/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
60 * and farmalloc(64K) returns a pointer with an offset of 8, so we
61 * must fix the pointer. Warning: the pointer must be put back to its
62 * original form in order to free it, use zcfree().
63 */
64
65#define MAX_PTR 10
66/* 10*64K = 640K */
67
68local int next_ptr = 0;
69
70typedef struct ptr_table_s {
71 voidpf org_ptr;
72 voidpf new_ptr;
73} ptr_table;
74
75local ptr_table table[MAX_PTR];
76/* This table is used to remember the original form of pointers
77 * to large buffers (64K). Such pointers are normalized with a zero offset.
78 * Since MSDOS is not a preemptive multitasking OS, this table is not
79 * protected from concurrent access. This hack doesn't work anyway on
80 * a protected system like OS/2. Use Microsoft C instead.
81 */
82
83voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
84{
85 voidpf buf = opaque; /* just to make some compilers happy */
86 ulg bsize = (ulg)items*size;
87
88 /* If we allocate less than 65520 bytes, we assume that farmalloc
89 * will return a usable pointer which doesn't have to be normalized.
90 */
91 if (bsize < 65520L) {
92 buf = farmalloc(bsize);
93 if (*(ush*)&buf != 0) return buf;
94 } else {
95 buf = farmalloc(bsize + 16L);
96 }
97 if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
98 table[next_ptr].org_ptr = buf;
99
100 /* Normalize the pointer to seg:0 */
101 *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
102 *(ush*)&buf = 0;
103 table[next_ptr++].new_ptr = buf;
104 return buf;
105}
106
107void zcfree (voidpf opaque, voidpf ptr)
108{
109 int n;
110 if (*(ush*)&ptr != 0) { /* object < 64K */
111 farfree(ptr);
112 return;
113 }
114 /* Find the original pointer */
115 for (n = 0; n < next_ptr; n++) {
116 if (ptr != table[n].new_ptr) continue;
117
118 farfree(table[n].org_ptr);
119 while (++n < next_ptr) {
120 table[n-1] = table[n];
121 }
122 next_ptr--;
123 return;
124 }
125 ptr = opaque; /* just to make some compilers happy */
126 Assert(0, "zcfree: ptr not found");
127}
128#endif
129#endif /* MSDOS && __TURBOC__ */
130
131
132#if defined(M_I86) && !defined(__32BIT__) && !defined( MY_ZCALLOC )
133/* Microsoft C in 16-bit mode */
134
135# define MY_ZCALLOC
136
137#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
138# define _halloc halloc
139# define _hfree hfree
140#endif
141
142voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
143{
144 if (opaque) opaque = 0; /* to make compiler happy */
145 return _halloc((long)items, size);
146}
147
148void zcfree (voidpf opaque, voidpf ptr)
149{
150 if (opaque) opaque = 0; /* to make compiler happy */
151 _hfree(ptr);
152}
153
154#endif /* MSC */
155
156
157#ifndef MY_ZCALLOC /* Any system without a special alloc function */
158
159#ifndef STDC
161extern void ft_sfree OF((voidpf ptr));
162#endif
163
165 voidpf opaque;
166 unsigned items;
167 unsigned size;
168{
169 if (opaque) items += size - size; /* make compiler happy */
170 return (voidpf)ft_scalloc(items, size);
171}
172
173void zcfree (opaque, ptr)
174 voidpf opaque;
175 voidpf ptr;
176{
177 ft_sfree(ptr);
178 if (opaque) return; /* make compiler happy */
179}
180
181#endif /* MY_ZCALLOC */
#define NULL
Definition: types.h:112
#define zmemzero(dest, len)
Definition: inflate.c:39
#define zmemcpy
Definition: inflate.c:38
#define Assert(cond, msg)
Definition: inflate.c:41
unsigned short ush
Definition: zlib.h:49
void FAR * voidpf
Definition: zlib.h:42
unsigned int uInt
Definition: zlib.h:38
unsigned long ulg
Definition: zlib.h:51
Byte FAR Bytef
Definition: zlib.h:41
unsigned char uch
Definition: zlib.h:47
int zmemcmp(Bytef *s1, const Bytef *s2, uInt len) const
Definition: zutil.c:28
void zcfree(voidpf opaque, voidpf ptr)
Definition: zutil.c:173
voidpf zcalloc(voidpf opaque, unsigned items, unsigned size)
Definition: zutil.c:164
#define local
Definition: zutil.h:30
#define ft_sfree
Definition: ftstdlib.h:133
#define ft_scalloc
Definition: ftstdlib.h:132
GLsizeiptr size
Definition: glext.h:5919
GLdouble n
Definition: glext.h:7729
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
struct S1 s1
struct S2 s2
static PVOID ptr
Definition: dispmode.c:27
static char * dest
Definition: rtl.c:135
static TCHAR * items[]
Definition: page1.c:45
#define exit(n)
Definition: config.h:202
Byte * voidp
Definition: zconf.h:420
#define OF(args)
Definition: zconf.h:295