~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/3rdparty/freetype/src/gzip/zutil.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: zutil.c,v 1.2 2002/11/06 22:32:54 davidT Exp $ */
 
7
 
 
8
#include "zutil.h"
 
9
 
 
10
#ifndef STDC
 
11
extern void exit OF((int));
 
12
#endif
 
13
 
 
14
 
 
15
#ifndef HAVE_MEMCPY
 
16
 
 
17
void zmemcpy(dest, source, len)
 
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
 
 
28
int zmemcmp(s1, s2, len)
 
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
 
 
41
void zmemzero(dest, len)
 
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
#ifdef __TURBOC__
 
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
 
 
68
local int next_ptr = 0;
 
69
 
 
70
typedef struct ptr_table_s {
 
71
    voidpf org_ptr;
 
72
    voidpf new_ptr;
 
73
} ptr_table;
 
74
 
 
75
local 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
 
 
83
voidpf 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
 
 
107
void  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 /* __TURBOC__ */
 
130
 
 
131
 
 
132
#if defined(M_I86) && !defined(__32BIT__)
 
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
 
 
142
voidpf 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
 
 
148
void  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
 
160
extern voidp  calloc OF((uInt items, uInt size));
 
161
extern void   free   OF((voidpf ptr));
 
162
#endif
 
163
 
 
164
voidpf zcalloc (opaque, items, size)
 
165
    voidpf opaque;
 
166
    unsigned items;
 
167
    unsigned size;
 
168
{
 
169
    if (opaque) items += size - size; /* make compiler happy */
 
170
    return (voidpf)calloc(items, size);
 
171
}
 
172
 
 
173
void  zcfree (opaque, ptr)
 
174
    voidpf opaque;
 
175
    voidpf ptr;
 
176
{
 
177
    free(ptr);
 
178
    if (opaque) return; /* make compiler happy */
 
179
}
 
180
 
 
181
#endif /* MY_ZCALLOC */