29#include FT_CONFIG_CONFIG_H
70 FT_CALLBACK_DEF(
void* )
71 ft_alloc( FT_Memory memory,
76 return ft_smalloc( (
size_t)size );
104 FT_CALLBACK_DEF(
void* )
105 ft_realloc( FT_Memory memory,
111 FT_UNUSED( cur_size );
113 return ft_srealloc( block, (
size_t)new_size );
132 FT_CALLBACK_DEF(
void )
133 ft_free( FT_Memory memory,
148#ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT
157#define FT_COMPONENT io
161#define STREAM_FILE( stream ) ( (FT_FILE*)stream->descriptor.pointer )
176 FT_CALLBACK_DEF(
void )
177 ft_ansi_stream_close( FT_Stream stream )
179 ft_fclose( STREAM_FILE( stream ) );
181 stream->descriptor.pointer = NULL;
213 FT_CALLBACK_DEF(
unsigned long )
214 ft_ansi_stream_io( FT_Stream stream,
215 unsigned long offset,
216 unsigned char* buffer,
217 unsigned long count )
222 if ( offset > stream->size && !count )
225 file = STREAM_FILE( stream );
227 if ( stream->pos != offset )
228 ft_fseek( file, (
long)offset, SEEK_SET );
235 return (
unsigned long)ft_fread( buffer, 1, count, file );
241 FT_BASE_DEF( FT_Error )
242 FT_Stream_Open( FT_Stream stream,
243 const char* filepathname )
249 return FT_THROW( Invalid_Stream_Handle );
251 stream->descriptor.pointer = NULL;
252 stream->pathname.pointer = (
char*)filepathname;
256 stream->close = NULL;
258 file = ft_fopen( filepathname,
"rb" );
261 FT_ERROR((
"FT_Stream_Open:"
262 " could not open `%s'\n", filepathname ));
264 return FT_THROW( Cannot_Open_Resource );
267 ft_fseek( file, 0, SEEK_END );
268 stream->size = (
unsigned long)ft_ftell( file );
271 FT_ERROR((
"FT_Stream_Open:" ));
272 FT_ERROR((
" opened `%s' but zero-sized\n", filepathname ));
274 return FT_THROW( Cannot_Open_Stream );
276 ft_fseek( file, 0, SEEK_SET );
278 stream->descriptor.pointer = file;
279 stream->read = ft_ansi_stream_io;
280 stream->close = ft_ansi_stream_close;
282 FT_TRACE1((
"FT_Stream_Open:" ));
283 FT_TRACE1((
" opened `%s' (%lu bytes) successfully\n",
284 filepathname, stream->size ));
291#ifdef FT_DEBUG_MEMORY
294 ft_mem_debug_init( FT_Memory memory );
297 ft_mem_debug_done( FT_Memory memory );
304 FT_BASE_DEF( FT_Memory )
305 FT_New_Memory(
void )
310 memory = (FT_Memory)ft_smalloc(
sizeof ( *memory ) );
314 memory->alloc = ft_alloc;
315 memory->realloc = ft_realloc;
316 memory->free = ft_free;
317#ifdef FT_DEBUG_MEMORY
318 ft_mem_debug_init( memory );
329 FT_Done_Memory( FT_Memory memory )
331#ifdef FT_DEBUG_MEMORY
332 ft_mem_debug_done( memory );