diff --git a/ChangeLog b/ChangeLog index cd198bc67..ead214a87 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2004-02-14 Masatake YAMATO + + * builds/unix/ftsystem.c: Include errno.h. + (ft_close_stream): Renamed to... + (ft_close_stream_by_munmap): This. + (ft_close_stream_by_free): New function. + (FT_Stream_Open): Use fallback method if mmap fails. + Use proper function for closing the stream. + +2004-02-14 Werner Lemberg + + * src/type1/t1load.c (parse_dict): Initialize `start_binary'. + 2004-02-13 Robert Etheridge * src/type42/t42objs.c (T42_Face_Init), src/type1/t1objs.c diff --git a/builds/unix/ftsystem.c b/builds/unix/ftsystem.c index 4ae260cd3..c7a34ad58 100644 --- a/builds/unix/ftsystem.c +++ b/builds/unix/ftsystem.c @@ -4,7 +4,7 @@ /* */ /* Unix-specific FreeType low-level system interface (body). */ /* */ -/* Copyright 1996-2001, 2002 by */ +/* Copyright 1996-2001, 2002, 2004 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -67,6 +67,7 @@ #include #include #include +#include /*************************************************************************/ @@ -182,16 +183,16 @@ /*************************************************************************/ /* */ /* */ - /* ft_close_stream */ + /* ft_close_stream_by_munmap */ /* */ /* */ - /* The function to close a stream. */ + /* The function to close a stream which is opened by mmap. */ /* */ /* */ /* stream :: A pointer to the stream object. */ /* */ FT_CALLBACK_DEF( void ) - ft_close_stream( FT_Stream stream ) + ft_close_stream_by_munmap( FT_Stream stream ) { munmap( (MUNMAP_ARG_CAST)stream->descriptor.pointer, stream->size ); @@ -201,6 +202,28 @@ } + /*************************************************************************/ + /* */ + /* */ + /* ft_close_stream_by_free */ + /* */ + /* */ + /* The function to close a stream which is created by ft_alloc. */ + /* */ + /* */ + /* stream :: A pointer to the stream object. */ + /* */ + FT_CALLBACK_DEF( void ) + ft_close_stream_by_free( FT_Stream stream ) + { + ft_free( NULL, stream->descriptor.pointer ); + + stream->descriptor.pointer = NULL; + stream->size = 0; + stream->base = 0; + } + + /* documentation is in ftobjs.h */ FT_EXPORT_DEF( FT_Error ) @@ -252,11 +275,49 @@ file, 0 ); - if ( (long)stream->base == -1 ) + if ( (long)stream->base != -1 ) + stream->close = ft_close_stream_by_munmap; + else { + ssize_t total_read_count; + + FT_ERROR(( "FT_Stream_Open:" )); FT_ERROR(( " could not `mmap' file `%s'\n", filepathname )); - goto Fail_Map; + + stream->base = ft_alloc( NULL, stream->size ); + + if ( !stream->base ) + { + FT_ERROR(( "FT_Stream_Open:" )); + FT_ERROR(( " could not `alloc' memory\n" )); + goto Fail_Map; + } + + total_read_count = 0; + do { + ssize_t read_count; + + + read_count = read( file, + stream->base + total_read_count, + stream->size - total_read_count ); + + if ( ( read_count == -1 ) ) + { + if ( errno == EINTR ) + continue; + + FT_ERROR(( "FT_Stream_Open:" )); + FT_ERROR(( " error while `read'ing file `%s'\n", filepathname )); + goto Fail_Read; + } + + total_read_count += read_count; + + } while ( total_read_count != stream->size ); + + stream->close = ft_close_stream_by_free; } close( file ); @@ -264,8 +325,7 @@ stream->descriptor.pointer = stream->base; stream->pathname.pointer = (char*)filepathname; - stream->close = ft_close_stream; - stream->read = 0; + stream->read = 0; FT_TRACE1(( "FT_Stream_Open:" )); FT_TRACE1(( " opened `%s' (%d bytes) successfully\n", @@ -273,6 +333,9 @@ return FT_Err_Ok; + Fail_Read: + ft_free( NULL, stream->base ); + Fail_Map: close( file ); diff --git a/src/type1/t1load.c b/src/type1/t1load.c index c5bc2a8c6..306544320 100644 --- a/src/type1/t1load.c +++ b/src/type1/t1load.c @@ -1504,7 +1504,7 @@ FT_Byte* keyword_flags ) { T1_Parser parser = &loader->parser; - FT_Byte *limit, *start_binary; + FT_Byte *limit, *start_binary = NULL; FT_Bool have_integer = 0;