Fix double-clicking control panel items
[reactos.git] / reactos / lib / freetype / rosglue.c
1 /* $Id$
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(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
23 #define TAG_FREETYPE TAG('F', 'T', 'Y', 'P')
24
25 /*
26 * First some generic routines
27 */
28
29 void *
30 memcpy(void *Dest, const void *Source, size_t Size)
31 {
32 RtlMoveMemory(Dest, Source, Size);
33
34 return Dest;
35 }
36
37
38 int
39 memcmp(const void *p1, const void *p2, size_t Size)
40 {
41 unsigned int i;
42 const char* s1;
43 const char* s2;
44
45 s1 = (const char *) p1;
46 s2 = (const char *) p2;
47 for (i = 0; i < Size; i++)
48 {
49 if ((*s1) != (*s2))
50 {
51 return((*s1) - (*s2));
52 }
53 s1++;
54 s2++;
55 }
56 return(0);
57 }
58
59 /* Hopefully we're only passed ASCII characters.... */
60 int
61 isalnum(int c)
62 {
63 assert(0x20 <= c && c <= 0x7f);
64
65 return (('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'));
66 }
67
68 long
69 labs(long j)
70 {
71 return (j < 0 ? -j : j);
72 }
73
74 /*
75 * Memory allocation
76 *
77 * Because of realloc, we need to keep track of the size of the allocated
78 * buffer (need to copy the old contents to the new buffer). So, allocate
79 * extra space for a size_t, store the allocated size in there and return
80 * the address just past it as the allocated buffer.
81 */
82
83 void *
84 malloc(size_t Size)
85 {
86 void *Object;
87
88 Object = ExAllocatePoolWithTag(PagedPool, sizeof(size_t) + Size, TAG_FREETYPE);
89 if (NULL != Object)
90 {
91 *((size_t *) Object) = Size;
92 Object = (void *)((size_t *) Object + 1);
93 }
94
95 return Object;
96 }
97
98 void *
99 realloc(void *Object, size_t Size)
100 {
101 void *NewObject;
102 size_t CopySize;
103
104 NewObject = ExAllocatePoolWithTag(PagedPool, sizeof(size_t) + Size, TAG_FREETYPE);
105 if (NULL != NewObject)
106 {
107 *((size_t *) NewObject) = Size;
108 NewObject = (void *)((size_t *) NewObject + 1);
109 CopySize = *((size_t *) Object - 1);
110 if (Size < CopySize)
111 {
112 CopySize = Size;
113 }
114 memcpy(NewObject, Object, CopySize);
115 ExFreePool((size_t *) Object - 1);
116 }
117
118 return NewObject;
119 }
120
121 void
122 free(void *Object)
123 {
124 ExFreePool((size_t *) Object - 1);
125 }
126
127 /*
128 * File I/O
129 *
130 * This is easy, we don't want FreeType to do any I/O. So return an
131 * error on each I/O attempt. Note that errno is not being set, it is
132 * not used by FreeType.
133 */
134
135 FILE *
136 fopen(const char *FileName, const char *Mode)
137 {
138 DPRINT1("Freetype tries to open file %s\n", FileName);
139
140 return NULL;
141 }
142
143 int
144 fseek(FILE *Stream, long Offset, int Origin)
145 {
146 DPRINT1("Doubleplus ungood: freetype shouldn't fseek!\n");
147
148 return -1;
149 }
150
151 long
152 ftell(FILE *Stream)
153 {
154 DPRINT1("Doubleplus ungood: freetype shouldn't ftell!\n");
155
156 return -1;
157 }
158
159 size_t
160 fread(void *Buffer, size_t Size, size_t Count, FILE *Stream)
161 {
162 DPRINT1("Doubleplus ungood: freetype shouldn't fread!\n");
163
164 return 0;
165 }
166
167 int
168 fclose(FILE *Stream)
169 {
170 DPRINT1("Doubleplus ungood: freetype shouldn't fclose!\n");
171
172 return EOF;
173 }