1 /***************************************************************************/
5 /* ANSI-specific FreeType low-level system interface (body). */
7 /* Copyright 1996-2000 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
18 /*************************************************************************/
20 /* This file contains the default interface used by FreeType to access */
21 /* low-level, i.e. memory management, i/o access as well as thread */
22 /* synchronisation. It can be replaced by user-specific routines if */
25 /*************************************************************************/
27 #include <ddk/ntddk.h>
29 #include <freetype/config/ftconfig.h>
30 #include <freetype/internal/ftdebug.h>
31 #include <freetype/ftsystem.h>
32 #include <freetype/fterrors.h>
33 #include <freetype/fttypes.h>
40 /*************************************************************************/
42 /* MEMORY MANAGEMENT INTERFACE */
44 /*************************************************************************/
46 /*************************************************************************/
48 /* It is not necessary to do any error checking for the */
49 /* allocation-related functions. This will be done by the higher level */
50 /* routines like FT_Alloc() or FT_Realloc(). */
52 /*************************************************************************/
55 /*************************************************************************/
61 /* The memory allocation function. */
64 /* memory :: A pointer to the memory object. */
66 /* size :: The requested size in bytes. */
69 /* block :: The address of newly allocated block. */
72 void* ft_alloc( FT_Memory memory,
77 /* return malloc( size ); */
78 return ExAllocatePool(NonPagedPool, size);
82 /*************************************************************************/
88 /* The memory reallocation function. */
91 /* memory :: A pointer to the memory object. */
93 /* cur_size :: The current size of the allocated memory block. */
95 /* new_size :: The newly requested size in bytes. */
97 /* block :: The current address of the block in memory. */
100 /* The address of the reallocated memory block. */
103 void* ft_realloc( FT_Memory memory,
109 FT_UNUSED( cur_size );
111 /* return realloc( block, new_size ); */
113 return ExAllocatePool(NonPagedPool, new_size);
117 /*************************************************************************/
123 /* The memory release function. */
126 /* memory :: A pointer to the memory object. */
128 /* block :: The address of block in memory to be freed. */
131 void ft_free( FT_Memory memory,
141 /*************************************************************************/
143 /* RESOURCE MANAGEMENT INTERFACE */
145 /*************************************************************************/
148 /*************************************************************************/
150 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
151 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
152 /* messages during execution. */
155 #define FT_COMPONENT trace_io
157 /* We use the macro STREAM_FILE for convenience to extract the */
158 /* system-specific stream handle from a given FreeType stream object */
159 #define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer )
162 /*************************************************************************/
165 /* ft_close_stream */
168 /* The function to close a stream. */
171 /* stream :: A pointer to the stream object. */
174 void ft_close_stream( FT_Stream stream )
176 DbgPrint("ftsystem.c: UNIMPLEMENTED CALL\n");
178 /* fclose( STREAM_FILE( stream ) ); */
180 stream->descriptor.pointer = NULL;
186 /*************************************************************************/
192 /* The function to open a stream. */
195 /* stream :: A pointer to the stream object. */
197 /* offset :: The position in the data stream to start reading. */
199 /* buffer :: The address of buffer to store the read data. */
201 /* count :: The number of bytes to read from the stream. */
204 /* The number of bytes actually read. */
207 unsigned long ft_io_stream( FT_Stream stream,
208 unsigned long offset,
209 unsigned char* buffer,
210 unsigned long count )
214 DbgPrint("ftsystem.c: UNIMPLEMENTED CALL\n");
215 file = STREAM_FILE( stream );
217 /* fseek( file, offset, SEEK_SET ); */
218 /* return (unsigned long)fread( buffer, 1, count, file ); */
222 /*************************************************************************/
228 /* Creates a new stream object. */
231 /* filepathname :: The name of the stream (usually a file) to be */
234 /* stream :: A pointer to the stream object. */
237 /* FreeType error code. 0 means success. */
239 FT_EXPORT_FUNC( FT_Error ) FT_New_Stream( const char* filepathname,
242 /* FILE* file; FIXME */
244 DbgPrint("ftsystem.c: UNIMPLEMENTED CALL\n");
247 return FT_Err_Invalid_Stream_Handle;
249 file = fopen( filepathname, "rb" );
252 FT_ERROR(( "FT_New_Stream:" ));
253 FT_ERROR(( " could not open `%s'\n", filepathname ));
255 return FT_Err_Cannot_Open_Resource;
258 fseek( file, 0, SEEK_END );
259 stream->size = ftell( file );
260 fseek( file, 0, SEEK_SET );
262 stream->descriptor.pointer = file;
263 stream->pathname.pointer = (char*)filepathname;
266 stream->read = ft_io_stream;
267 stream->close = ft_close_stream;
269 FT_TRACE1(( "FT_New_Stream:" ));
270 FT_TRACE1(( " opened `%s' (%d bytes) successfully\n",
271 filepathname, stream->size )); */
277 /*************************************************************************/
283 /* Creates a new memory object. */
286 /* A pointer to the new memory object. 0 in case of error. */
288 FT_EXPORT_FUNC( FT_Memory ) FT_New_Memory( void )
292 /* memory = (FT_Memory)malloc( sizeof ( *memory ) ); */
294 memory = ExAllocatePool(NonPagedPool, sizeof(*memory));
298 memory->alloc = ft_alloc;
299 memory->realloc = ft_realloc;
300 memory->free = ft_free;