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