1
/***************************************************************************/
5
/* ANSI-specific FreeType low-level system interface (body). */
7
/* Copyright 1996-2001, 2002 by */
8
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
10
/* Modified for XFree86. */
12
/* This file is part of the FreeType project, and may only be used, */
13
/* modified, and distributed under the terms of the FreeType project */
14
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
15
/* this file you indicate that you have read the license and */
16
/* understand and accept it fully. */
18
/***************************************************************************/
20
/* Modified for XFree86 */
23
/*************************************************************************/
25
/* This file contains the default interface used by FreeType to access */
26
/* low-level, i.e. memory management, i/o access as well as thread */
27
/* synchronisation. It can be replaced by user-specific routines if */
30
/*************************************************************************/
37
#include FT_CONFIG_CONFIG_H
47
#define _XTYPEDEF_BOOL
49
#define DONT_DEFINE_WRAPPERS
50
#include "xf86_ansic.h"
51
#undef DONT_DEFINE_WRAPPERS
52
#define malloc(x) xf86malloc(x)
53
#define realloc(x, y) xf86realloc(x, y)
54
#define free(x) xf86free(x)
56
#define fopen(x, y) xf86fopen(x, y)
57
#define fclose(x) xf86fclose(x)
58
#define fseek(x, y, z) xf86fseek(x, y, z)
59
#define ftell(x) xf86ftell(x)
60
#define SEEK_SET XF86_SEEK_SET
61
#define SEEK_END XF86_SEEK_END
62
#define fread(x, y, z, t) xf86fread(x, y, z, t)
66
/*************************************************************************/
68
/* MEMORY MANAGEMENT INTERFACE */
70
/*************************************************************************/
72
/*************************************************************************/
74
/* It is not necessary to do any error checking for the */
75
/* allocation-related functions. This will be done by the higher level */
76
/* routines like FT_Alloc() or FT_Realloc(). */
78
/*************************************************************************/
81
/*************************************************************************/
87
/* The memory allocation function. */
90
/* memory :: A pointer to the memory object. */
92
/* size :: The requested size in bytes. */
95
/* The address of newly allocated block. */
97
FT_CALLBACK_DEF( void* )
98
ft_alloc( FT_Memory memory,
103
return malloc( size );
107
/*************************************************************************/
113
/* The memory reallocation function. */
116
/* memory :: A pointer to the memory object. */
118
/* cur_size :: The current size of the allocated memory block. */
120
/* new_size :: The newly requested size in bytes. */
122
/* block :: The current address of the block in memory. */
125
/* The address of the reallocated memory block. */
127
FT_CALLBACK_DEF( void* )
128
ft_realloc( FT_Memory memory,
134
FT_UNUSED( cur_size );
136
return realloc( block, new_size );
140
/*************************************************************************/
146
/* The memory release function. */
149
/* memory :: A pointer to the memory object. */
151
/* block :: The address of block in memory to be freed. */
153
FT_CALLBACK_DEF( void )
154
ft_free( FT_Memory memory,
163
/*************************************************************************/
165
/* RESOURCE MANAGEMENT INTERFACE */
167
/*************************************************************************/
170
/*************************************************************************/
172
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
173
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
174
/* messages during execution. */
177
#define FT_COMPONENT trace_io
179
/* We use the macro STREAM_FILE for convenience to extract the */
180
/* system-specific stream handle from a given FreeType stream object */
181
#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer )
184
/*************************************************************************/
187
/* ft_ansi_stream_close */
190
/* The function to close a stream. */
193
/* stream :: A pointer to the stream object. */
195
FT_CALLBACK_DEF( void )
196
ft_ansi_stream_close( FT_Stream stream )
198
fclose( STREAM_FILE( stream ) );
200
stream->descriptor.pointer = NULL;
206
/*************************************************************************/
209
/* ft_ansi_stream_io */
212
/* The function to open a stream. */
215
/* stream :: A pointer to the stream object. */
217
/* offset :: The position in the data stream to start reading. */
219
/* buffer :: The address of buffer to store the read data. */
221
/* count :: The number of bytes to read from the stream. */
224
/* The number of bytes actually read. */
226
FT_CALLBACK_DEF( unsigned long )
227
ft_ansi_stream_io( FT_Stream stream,
228
unsigned long offset,
229
unsigned char* buffer,
230
unsigned long count )
235
file = STREAM_FILE( stream );
237
fseek( file, offset, SEEK_SET );
239
return (unsigned long)fread( buffer, 1, count, file );
243
/* documentation is in ftobjs.h */
245
FT_EXPORT_DEF( FT_Error )
246
FT_Stream_Open( FT_Stream stream,
247
const char* filepathname )
253
return FT_Err_Invalid_Stream_Handle;
255
file = fopen( filepathname, "rb" );
258
FT_ERROR(( "FT_Stream_Open:" ));
259
FT_ERROR(( " could not open `%s'\n", filepathname ));
261
return FT_Err_Cannot_Open_Resource;
264
fseek( file, 0, SEEK_END );
265
stream->size = ftell( file );
266
fseek( file, 0, SEEK_SET );
268
stream->descriptor.pointer = file;
269
stream->pathname.pointer = (char*)filepathname;
272
stream->read = ft_ansi_stream_io;
273
stream->close = ft_ansi_stream_close;
275
FT_TRACE1(( "FT_Stream_Open:" ));
276
FT_TRACE1(( " opened `%s' (%d bytes) successfully\n",
277
filepathname, stream->size ));
283
#ifdef FT_DEBUG_MEMORY
286
ft_mem_debug_init( FT_Memory memory );
289
ft_mem_debug_done( FT_Memory memory );
294
/* documentation is in ftobjs.h */
296
FT_EXPORT_DEF( FT_Memory )
297
FT_New_Memory( void )
302
memory = (FT_Memory)malloc( sizeof ( *memory ) );
306
memory->alloc = ft_alloc;
307
memory->realloc = ft_realloc;
308
memory->free = ft_free;
309
#ifdef FT_DEBUG_MEMORY
310
ft_mem_debug_init( memory );
318
/* documentation is in ftobjs.h */
320
FT_EXPORT_DEF( void )
321
FT_Done_Memory( FT_Memory memory )
323
#ifdef FT_DEBUG_MEMORY
324
ft_mem_debug_done( memory );
327
memory->free( memory, memory );