1 /***************************************************************************/
5 /* VMS-specific FreeType low-level system interface (body). */
7 /* Copyright 1996-2001, 2002, 2005, 2010 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 /***************************************************************************/
20 /* we use our special ftconfig.h file, not the standard one */
22 #include FT_INTERNAL_DEBUG_H
26 #include FT_INTERNAL_OBJECTS_H
28 /* memory-mapping includes and definitions */
38 #ifdef MUNMAP_USES_VOIDP
39 #define MUNMAP_ARG_CAST void *
41 #define MUNMAP_ARG_CAST char *
44 #ifdef NEED_MUNMAP_DECL
55 #define MUNMAP_ARG_CAST char *
57 #endif /* NEED_DECLARATION_MUNMAP */
60 #include <sys/types.h>
72 /*************************************************************************/
74 /* MEMORY MANAGEMENT INTERFACE */
76 /*************************************************************************/
79 /*************************************************************************/
85 /* The memory allocation function. */
88 /* memory :: A pointer to the memory object. */
90 /* size :: The requested size in bytes. */
93 /* The address of newly allocated block. */
95 FT_CALLBACK_DEF( void* )
96 ft_alloc( FT_Memory memory,
101 return malloc( size );
105 /*************************************************************************/
111 /* The memory reallocation function. */
114 /* memory :: A pointer to the memory object. */
116 /* cur_size :: The current size of the allocated memory block. */
118 /* new_size :: The newly requested size in bytes. */
120 /* block :: The current address of the block in memory. */
123 /* The address of the reallocated memory block. */
125 FT_CALLBACK_DEF( void* )
126 ft_realloc( FT_Memory memory,
132 FT_UNUSED( cur_size );
134 return realloc( block, new_size );
138 /*************************************************************************/
144 /* The memory release function. */
147 /* memory :: A pointer to the memory object. */
149 /* block :: The address of block in memory to be freed. */
151 FT_CALLBACK_DEF( void )
152 ft_free( FT_Memory memory,
161 /*************************************************************************/
163 /* RESOURCE MANAGEMENT INTERFACE */
165 /*************************************************************************/
168 /*************************************************************************/
170 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
171 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
172 /* messages during execution. */
175 #define FT_COMPONENT trace_io
177 /* We use the macro STREAM_FILE for convenience to extract the */
178 /* system-specific stream handle from a given FreeType stream object */
179 #define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer )
182 /*************************************************************************/
185 /* ft_close_stream */
188 /* The function to close a stream. */
191 /* stream :: A pointer to the stream object. */
193 FT_CALLBACK_DEF( void )
194 ft_close_stream( FT_Stream stream )
196 munmap( (MUNMAP_ARG_CAST)stream->descriptor.pointer, stream->size );
198 stream->descriptor.pointer = NULL;
204 /* documentation is in ftobjs.h */
206 FT_BASE_DEF( FT_Error )
207 FT_Stream_Open( FT_Stream stream,
208 const char* filepathname )
211 struct stat stat_buf;
215 return FT_Err_Invalid_Stream_Handle;
218 file = open( filepathname, O_RDONLY );
221 FT_ERROR(( "FT_Stream_Open:" ));
222 FT_ERROR(( " could not open `%s'\n", filepathname ));
223 return FT_Err_Cannot_Open_Resource;
226 if ( fstat( file, &stat_buf ) < 0 )
228 FT_ERROR(( "FT_Stream_Open:" ));
229 FT_ERROR(( " could not `fstat' file `%s'\n", filepathname ));
233 stream->size = stat_buf.st_size;
236 FT_ERROR(( "FT_Stream_Open:" ));
237 FT_ERROR(( " opened `%s' but zero-sized\n", filepathname ));
242 stream->base = (unsigned char *)mmap( NULL,
245 MAP_FILE | MAP_PRIVATE,
249 if ( (long)stream->base == -1 )
251 FT_ERROR(( "FT_Stream_Open:" ));
252 FT_ERROR(( " could not `mmap' file `%s'\n", filepathname ));
258 stream->descriptor.pointer = stream->base;
259 stream->pathname.pointer = (char*)filepathname;
261 stream->close = ft_close_stream;
264 FT_TRACE1(( "FT_Stream_Open:" ));
265 FT_TRACE1(( " opened `%s' (%d bytes) successfully\n",
266 filepathname, stream->size ));
277 return FT_Err_Cannot_Open_Stream;
281 #ifdef FT_DEBUG_MEMORY
284 ft_mem_debug_init( FT_Memory memory );
287 ft_mem_debug_done( FT_Memory memory );
292 /* documentation is in ftobjs.h */
294 FT_BASE_DEF( FT_Memory )
295 FT_New_Memory( void )
300 memory = (FT_Memory)malloc( sizeof ( *memory ) );
304 memory->alloc = ft_alloc;
305 memory->realloc = ft_realloc;
306 memory->free = ft_free;
307 #ifdef FT_DEBUG_MEMORY
308 ft_mem_debug_init( memory );
316 /* documentation is in ftobjs.h */
319 FT_Done_Memory( FT_Memory memory )
321 #ifdef FT_DEBUG_MEMORY
322 ft_mem_debug_done( memory );
324 memory->free( memory, memory );