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