2004-10-28 Casper S. Hornstrup <chorns@users.sourceforge.net>
[reactos.git] / reactos / lib / freetype / rosglue.c
1 /* $Id: rosglue.c,v 1.2 2003/04/01 17:14:36 gvg Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: FreeType implementation for ReactOS
5 * PURPOSE: Glue functions between FreeType
6 * FILE: thirdparty/freetype/rosglue.c
7 * PROGRAMMER: Ge van Geldorp (ge@gse.nl)
8 * NOTES:
9 */
10
11 #include <ddk/ntddk.h>
12 #include <ctype.h>
13 #include <errno.h>
14 #include <setjmp.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18
19 #define NDEBUG
20 #include <debug.h>
21
22 #define TAG_FREETYPE TAG('F', 'T', 'Y', 'P')
23
24 /*
25 * First some generic routines
26 */
27
28 void *
29 memcpy(void *Dest, const void *Source, size_t Size)
30 {
31 RtlMoveMemory(Dest, Source, Size);
32
33 return Dest;
34 }
35
36
37 int
38 memcmp(const void *p1, const void *p2, size_t Size)
39 {
40 unsigned int i;
41 const char* s1;
42 const char* s2;
43
44 s1 = (const char *) p1;
45 s2 = (const char *) p2;
46 for (i = 0; i < Size; i++)
47 {
48 if ((*s1) != (*s2))
49 {
50 return((*s1) - (*s2));
51 }
52 s1++;
53 s2++;
54 }
55 return(0);
56 }
57
58 /* Hopefully we're only passed ASCII characters.... */
59 int
60 isalnum(int c)
61 {
62 assert(0x20 <= c && c <= 0x7f);
63
64 return (('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'));
65 }
66
67 long
68 labs(long j)
69 {
70 return (j < 0 ? -j : j);
71 }
72
73 /*
74 * Memory allocation
75 *
76 * Because of realloc, we need to keep track of the size of the allocated
77 * buffer (need to copy the old contents to the new buffer). So, allocate
78 * extra space for a size_t, store the allocated size in there and return
79 * the address just past it as the allocated buffer.
80 */
81
82 void *
83 malloc(size_t Size)
84 {
85 void *Object;
86
87 Object = ExAllocatePoolWithTag(NonPagedPool, sizeof(size_t) + Size, TAG_FREETYPE);
88 if (NULL != Object)
89 {
90 *((size_t *) Object) = Size;
91 Object = (void *)((size_t *) Object + 1);
92 }
93
94 return Object;
95 }
96
97 void *
98 realloc(void *Object, size_t Size)
99 {
100 void *NewObject;
101 size_t CopySize;
102
103 NewObject = ExAllocatePoolWithTag(NonPagedPool, sizeof(size_t) + Size, TAG_FREETYPE);
104 if (NULL != NewObject)
105 {
106 *((size_t *) NewObject) = Size;
107 NewObject = (void *)((size_t *) NewObject + 1);
108 CopySize = *((size_t *) Object - 1);
109 if (Size < CopySize)
110 {
111 CopySize = Size;
112 }
113 memcpy(NewObject, Object, CopySize);
114 ExFreePool((size_t *) Object - 1);
115 }
116
117 return NewObject;
118 }
119
120 void
121 free(void *Object)
122 {
123 ExFreePool((size_t *) Object - 1);
124 }
125
126 /*
127 * File I/O
128 *
129 * This is easy, we don't want FreeType to do any I/O. So return an
130 * error on each I/O attempt. Note that errno is not being set, it is
131 * not used by FreeType.
132 */
133
134 FILE *
135 fopen(const char *FileName, const char *Mode)
136 {
137 DPRINT1("Freetype tries to open file %s\n", FileName);
138
139 return NULL;
140 }
141
142 int
143 fseek(FILE *Stream, long Offset, int Origin)
144 {
145 DPRINT1("Doubleplus ungood: freetype shouldn't fseek!\n");
146
147 return -1;
148 }
149
150 long
151 ftell(FILE *Stream)
152 {
153 DPRINT1("Doubleplus ungood: freetype shouldn't ftell!\n");
154
155 return -1;
156 }
157
158 size_t
159 fread(void *Buffer, size_t Size, size_t Count, FILE *Stream)
160 {
161 DPRINT1("Doubleplus ungood: freetype shouldn't fread!\n");
162
163 return 0;
164 }
165
166 int
167 fclose(FILE *Stream)
168 {
169 DPRINT1("Doubleplus ungood: freetype shouldn't fclose!\n");
170
171 return EOF;
172 }