Sync with trunk head (part 1 of x)
[reactos.git] / drivers / video / font / ftfd / rosglue.c
1 /* $Id: rosglue.c 39928 2009-03-10 02:49:45Z tkreuzer $
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 <stdarg.h>
12 #include <stdio.h>
13 #include <windef.h>
14 #include <wingdi.h>
15 #include <winddi.h>
16
17 #define NDEBUG
18 #include <debug.h>
19
20 #define TAG_FREETYPE 'PYTF'
21
22 /*
23 * First some generic routines
24 */
25
26 ULONG
27 DbgPrint(IN PCCH Format, IN ...)
28 {
29 va_list args;
30
31 va_start(args, Format);
32 EngDebugPrint("ft2: ", (PCHAR)Format, args);
33 va_end(args);
34 return 0;
35 }
36
37 /*
38 * Memory allocation
39 *
40 * Because of realloc, we need to keep track of the size of the allocated
41 * buffer (need to copy the old contents to the new buffer). So, allocate
42 * extra space for a size_t, store the allocated size in there and return
43 * the address just past it as the allocated buffer.
44 */
45
46 void *
47 malloc(size_t Size)
48 {
49 void *Object;
50
51 Object = EngAllocMem(0, sizeof(size_t) + Size, TAG_FREETYPE);
52 if (NULL != Object)
53 {
54 *((size_t *) Object) = Size;
55 Object = (void *)((size_t *) Object + 1);
56 }
57
58 return Object;
59 }
60
61 void *
62 realloc(void *Object, size_t Size)
63 {
64 void *NewObject;
65 size_t CopySize;
66
67 NewObject = EngAllocMem(0, sizeof(size_t) + Size, TAG_FREETYPE);
68 if (NULL != NewObject)
69 {
70 *((size_t *) NewObject) = Size;
71 NewObject = (void *)((size_t *) NewObject + 1);
72 CopySize = *((size_t *) Object - 1);
73 if (Size < CopySize)
74 {
75 CopySize = Size;
76 }
77 memcpy(NewObject, Object, CopySize);
78 EngFreeMem((size_t *) Object - 1);
79 }
80
81 return NewObject;
82 }
83
84 void
85 free(void *Object)
86 {
87 EngFreeMem((size_t *) Object - 1);
88 }
89
90 /*
91 * File I/O
92 *
93 * This is easy, we don't want FreeType to do any I/O. So return an
94 * error on each I/O attempt. Note that errno is not being set, it is
95 * not used by FreeType.
96 */
97
98 FILE *
99 fopen(const char *FileName, const char *Mode)
100 {
101 DPRINT1("Freetype tries to open file %s\n", FileName);
102
103 return NULL;
104 }
105
106 int
107 fseek(FILE *Stream, long Offset, int Origin)
108 {
109 DPRINT1("Doubleplus ungood: freetype shouldn't fseek!\n");
110
111 return -1;
112 }
113
114 long
115 ftell(FILE *Stream)
116 {
117 DPRINT1("Doubleplus ungood: freetype shouldn't ftell!\n");
118
119 return -1;
120 }
121
122 size_t
123 fread(void *Buffer, size_t Size, size_t Count, FILE *Stream)
124 {
125 DPRINT1("Doubleplus ungood: freetype shouldn't fread!\n");
126
127 return 0;
128 }
129
130 int
131 fclose(FILE *Stream)
132 {
133 DPRINT1("Doubleplus ungood: freetype shouldn't fclose!\n");
134
135 return EOF;
136 }