Suggestion from "mgh".
[open-ps2-loader.git] / thirdparty / freetype-2.3.12 / builds / vms / ftsystem.c
blob76bfae9f404e7781ae2cc2b5a9f24126215016fe
1 /***************************************************************************/
2 /* */
3 /* ftsystem.c */
4 /* */
5 /* VMS-specific FreeType low-level system interface (body). */
6 /* */
7 /* Copyright 1996-2001, 2002, 2005 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
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. */
15 /* */
16 /***************************************************************************/
19 #include <ft2build.h>
20 /* we use our special ftconfig.h file, not the standard one */
21 #include <ftconfig.h>
22 #include FT_INTERNAL_DEBUG_H
23 #include FT_SYSTEM_H
24 #include FT_ERRORS_H
25 #include FT_TYPES_H
26 #include FT_INTERNAL_OBJECTS_H
28 /* memory-mapping includes and definitions */
29 #ifdef HAVE_UNISTD_H
30 #include <unistd.h>
31 #endif
33 #include <sys/mman.h>
34 #ifndef MAP_FILE
35 #define MAP_FILE 0x00
36 #endif
38 #ifdef MUNMAP_USES_VOIDP
39 #define MUNMAP_ARG_CAST void *
40 #else
41 #define MUNMAP_ARG_CAST char *
42 #endif
44 #ifdef NEED_MUNMAP_DECL
46 #ifdef __cplusplus
47 extern "C"
48 #else
49 extern
50 #endif
51 int
52 munmap( char* addr,
53 int len );
55 #define MUNMAP_ARG_CAST char *
57 #endif /* NEED_DECLARATION_MUNMAP */
60 #include <sys/types.h>
61 #include <sys/stat.h>
63 #ifdef HAVE_FCNTL_H
64 #include <fcntl.h>
65 #endif
67 #include <stdio.h>
68 #include <stdlib.h>
69 #include <string.h>
72 /*************************************************************************/
73 /* */
74 /* MEMORY MANAGEMENT INTERFACE */
75 /* */
76 /*************************************************************************/
79 /*************************************************************************/
80 /* */
81 /* <Function> */
82 /* ft_alloc */
83 /* */
84 /* <Description> */
85 /* The memory allocation function. */
86 /* */
87 /* <Input> */
88 /* memory :: A pointer to the memory object. */
89 /* */
90 /* size :: The requested size in bytes. */
91 /* */
92 /* <Return> */
93 /* The address of newly allocated block. */
94 /* */
95 FT_CALLBACK_DEF( void* )
96 ft_alloc( FT_Memory memory,
97 long size )
99 FT_UNUSED( memory );
101 return malloc( size );
105 /*************************************************************************/
106 /* */
107 /* <Function> */
108 /* ft_realloc */
109 /* */
110 /* <Description> */
111 /* The memory reallocation function. */
112 /* */
113 /* <Input> */
114 /* memory :: A pointer to the memory object. */
115 /* */
116 /* cur_size :: The current size of the allocated memory block. */
117 /* */
118 /* new_size :: The newly requested size in bytes. */
119 /* */
120 /* block :: The current address of the block in memory. */
121 /* */
122 /* <Return> */
123 /* The address of the reallocated memory block. */
124 /* */
125 FT_CALLBACK_DEF( void* )
126 ft_realloc( FT_Memory memory,
127 long cur_size,
128 long new_size,
129 void* block )
131 FT_UNUSED( memory );
132 FT_UNUSED( cur_size );
134 return realloc( block, new_size );
138 /*************************************************************************/
139 /* */
140 /* <Function> */
141 /* ft_free */
142 /* */
143 /* <Description> */
144 /* The memory release function. */
145 /* */
146 /* <Input> */
147 /* memory :: A pointer to the memory object. */
148 /* */
149 /* block :: The address of block in memory to be freed. */
150 /* */
151 FT_CALLBACK_DEF( void )
152 ft_free( FT_Memory memory,
153 void* block )
155 FT_UNUSED( memory );
157 free( block );
161 /*************************************************************************/
162 /* */
163 /* RESOURCE MANAGEMENT INTERFACE */
164 /* */
165 /*************************************************************************/
168 /*************************************************************************/
169 /* */
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. */
173 /* */
174 #undef FT_COMPONENT
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 /*************************************************************************/
183 /* */
184 /* <Function> */
185 /* ft_close_stream */
186 /* */
187 /* <Description> */
188 /* The function to close a stream. */
189 /* */
190 /* <Input> */
191 /* stream :: A pointer to the stream object. */
192 /* */
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;
199 stream->size = 0;
200 stream->base = 0;
204 /* documentation is in ftobjs.h */
206 FT_BASE_DEF( FT_Error )
207 FT_Stream_Open( FT_Stream stream,
208 const char* filepathname )
210 int file;
211 struct stat stat_buf;
214 if ( !stream )
215 return FT_Err_Invalid_Stream_Handle;
217 /* open the file */
218 file = open( filepathname, O_RDONLY );
219 if ( file < 0 )
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 ));
230 goto Fail_Map;
233 stream->size = stat_buf.st_size;
234 stream->pos = 0;
235 stream->base = (unsigned char *)mmap( NULL,
236 stream->size,
237 PROT_READ,
238 MAP_FILE | MAP_PRIVATE,
239 file,
240 0 );
242 if ( (long)stream->base == -1 )
244 FT_ERROR(( "FT_Stream_Open:" ));
245 FT_ERROR(( " could not `mmap' file `%s'\n", filepathname ));
246 goto Fail_Map;
249 close( file );
251 stream->descriptor.pointer = stream->base;
252 stream->pathname.pointer = (char*)filepathname;
254 stream->close = ft_close_stream;
255 stream->read = 0;
257 FT_TRACE1(( "FT_Stream_Open:" ));
258 FT_TRACE1(( " opened `%s' (%d bytes) successfully\n",
259 filepathname, stream->size ));
261 return FT_Err_Ok;
263 Fail_Map:
264 close( file );
266 stream->base = NULL;
267 stream->size = 0;
268 stream->pos = 0;
270 return FT_Err_Cannot_Open_Stream;
274 #ifdef FT_DEBUG_MEMORY
276 extern FT_Int
277 ft_mem_debug_init( FT_Memory memory );
279 extern void
280 ft_mem_debug_done( FT_Memory memory );
282 #endif
285 /* documentation is in ftobjs.h */
287 FT_BASE_DEF( FT_Memory )
288 FT_New_Memory( void )
290 FT_Memory memory;
293 memory = (FT_Memory)malloc( sizeof ( *memory ) );
294 if ( memory )
296 memory->user = 0;
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 );
302 #endif
305 return memory;
309 /* documentation is in ftobjs.h */
311 FT_BASE_DEF( void )
312 FT_Done_Memory( FT_Memory memory )
314 #ifdef FT_DEBUG_MEMORY
315 ft_mem_debug_done( memory );
316 #endif
317 memory->free( memory, memory );
321 /* END */