1 /***************************************************************************/
5 /* VMS-specific FreeType low-level system interface (body). */
7 /* Copyright 1996-2001, 2002, 2005 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
;
235 stream
->base
= (unsigned char *)mmap( NULL
,
238 MAP_FILE
| MAP_PRIVATE
,
242 if ( (long)stream
->base
== -1 )
244 FT_ERROR(( "FT_Stream_Open:" ));
245 FT_ERROR(( " could not `mmap' file `%s'\n", filepathname
));
251 stream
->descriptor
.pointer
= stream
->base
;
252 stream
->pathname
.pointer
= (char*)filepathname
;
254 stream
->close
= ft_close_stream
;
257 FT_TRACE1(( "FT_Stream_Open:" ));
258 FT_TRACE1(( " opened `%s' (%d bytes) successfully\n",
259 filepathname
, stream
->size
));
270 return FT_Err_Cannot_Open_Stream
;
274 #ifdef FT_DEBUG_MEMORY
277 ft_mem_debug_init( FT_Memory memory
);
280 ft_mem_debug_done( FT_Memory memory
);
285 /* documentation is in ftobjs.h */
287 FT_BASE_DEF( FT_Memory
)
288 FT_New_Memory( void )
293 memory
= (FT_Memory
)malloc( sizeof ( *memory
) );
297 memory
->alloc
= ft_alloc
;
298 memory
->realloc
= ft_realloc
;
299 memory
->free
= ft_free
;
300 #ifdef FT_DEBUG_MEMORY
301 ft_mem_debug_init( memory
);
309 /* documentation is in ftobjs.h */
312 FT_Done_Memory( FT_Memory memory
)
314 #ifdef FT_DEBUG_MEMORY
315 ft_mem_debug_done( memory
);
317 memory
->free( memory
, memory
);