22 #include FT_INTERNAL_DEBUG_H 26 #include FT_INTERNAL_STREAM_H 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 * 60 #include <sys/types.h> 135 return realloc( block, new_size );
176 #define FT_COMPONENT trace_io 180 #define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer ) 199 stream->descriptor.pointer =
NULL;
231 const char* filepathname )
234 struct stat stat_buf;
238 return FT_Err_Invalid_Stream_Handle;
241 file =
open( filepathname, O_RDONLY );
245 FT_ERROR((
" could not open `%s'\n", filepathname ));
246 return FT_Err_Cannot_Open_Resource;
256 (
void)fcntl( file, F_SETFD, FD_CLOEXEC );
258 (
void)fcntl( file, F_SETFD, 1 );
262 if ( fstat( file, &stat_buf ) < 0 )
265 FT_ERROR((
" could not `fstat' file `%s'\n", filepathname ));
278 if ( stat_buf.st_size > LONG_MAX )
280 FT_ERROR((
"FT_Stream_Open: file is too big\n" ));
283 else if ( stat_buf.st_size == 0 )
285 FT_ERROR((
"FT_Stream_Open: zero-length file\n" ));
290 stream->size = (
unsigned long)stat_buf.st_size;
304 ssize_t total_read_count;
308 FT_ERROR((
" could not `mmap' file `%s'\n", filepathname ));
315 FT_ERROR((
" could not `alloc' memory\n" ));
319 total_read_count = 0;
324 read_count =
read( file,
325 stream->base + total_read_count,
326 stream->size - total_read_count );
328 if ( read_count <= 0 )
330 if ( read_count == -1 && errno == EINTR )
334 FT_ERROR((
" error while `read'ing file `%s'\n", filepathname ));
338 total_read_count += read_count;
340 }
while ( (
unsigned long)total_read_count !=
stream->size );
348 stream->pathname.pointer = (
char*)filepathname;
353 FT_TRACE1((
" opened `%s' (%d bytes) successfully\n",
354 filepathname,
stream->size ));
368 return FT_Err_Cannot_Open_Stream;
372 #ifdef FT_DEBUG_MEMORY 398 #ifdef FT_DEBUG_MEMORY 399 ft_mem_debug_init( memory );
412 #ifdef FT_DEBUG_MEMORY 413 ft_mem_debug_done( memory );
415 memory->free( memory, memory );
int read(int fd, char *buf, int nbytes)
ft_close_stream_by_munmap(FT_Stream stream)
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
#define FT_TRACE1(varformat)
#define FT_ERROR(varformat)
FT_Stream_Open(FT_Stream stream, const char *filepathname)
GLenum const GLvoid * addr
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
#define FT_CALLBACK_DEF(x)
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
ft_free(FT_Memory memory, void *block)
int open(const char *name, int flags, int mode)
ft_close_stream_by_free(FT_Stream stream)
ft_alloc(FT_Memory memory, long size)
FT_Done_Memory(FT_Memory memory)
ft_realloc(FT_Memory memory, long cur_size, long new_size, void *block)