X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fgzip%2Fftgzip.c;h=2d4200d9fa164bf7b5f973678f0afb355b371d93;hb=afcae9b7a0a6009d33581fac78416fc9623a8a18;hp=f3d2ef94fcd1d6ab3a2910bfa131a0b0ad84ab8d;hpb=46ec2c26b7d34b4a37c96ed6049ce3fd0702dc78;p=framework%2Fgraphics%2Ffreetype.git diff --git a/src/gzip/ftgzip.c b/src/gzip/ftgzip.c index f3d2ef9..2d4200d 100644 --- a/src/gzip/ftgzip.c +++ b/src/gzip/ftgzip.c @@ -8,7 +8,7 @@ /* parse compressed PCF fonts, as found with many X11 server */ /* distributions. */ /* */ -/* Copyright 2002-2006, 2009-2012 by */ +/* Copyright 2002-2006, 2009-2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -68,6 +68,15 @@ #undef SLOW #define SLOW 1 /* we can't use asm-optimized sources here! */ +#if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */ + /* We disable the warning `conversion from XXX to YYY, */ + /* possible loss of data' in order to compile cleanly with */ + /* the maximum level of warnings: zlib is non-FreeType */ + /* code. */ +#pragma warning( push ) +#pragma warning( disable : 4244 ) +#endif /* _MSC_VER */ + /* Urgh. `inflate_mask' must not be declared twice -- C++ doesn't like this. We temporarily disable it and load all necessary header files. */ #define NO_INFLATE_MASK @@ -87,6 +96,10 @@ #include "inflate.c" #include "adler32.c" +#if defined( _MSC_VER ) +#pragma warning( pop ) +#endif + #endif /* !FT_CONFIG_OPTION_SYSTEM_ZLIB */ @@ -195,12 +208,12 @@ /* head[0] && head[1] are the magic numbers; */ /* head[2] is the method, and head[3] the flags */ - if ( head[0] != 0x1f || - head[1] != 0x8b || + if ( head[0] != 0x1F || + head[1] != 0x8B || head[2] != Z_DEFLATED || (head[3] & FT_GZIP_RESERVED) ) { - error = Gzip_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Exit; } @@ -262,7 +275,7 @@ FT_Stream source ) { z_stream* zstream = &zip->zstream; - FT_Error error = Gzip_Err_Ok; + FT_Error error = FT_Err_Ok; zip->stream = stream; @@ -294,7 +307,7 @@ if ( inflateInit2( zstream, -MAX_WBITS ) != Z_OK || zstream->next_in == NULL ) - error = Gzip_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); Exit: return error; @@ -365,7 +378,7 @@ size = stream->read( stream, stream->pos, zip->input, FT_GZIP_BUFFER_SIZE ); if ( size == 0 ) - return Gzip_Err_Invalid_Stream_Operation; + return FT_THROW( Invalid_Stream_Operation ); } else { @@ -374,7 +387,7 @@ size = FT_GZIP_BUFFER_SIZE; if ( size == 0 ) - return Gzip_Err_Invalid_Stream_Operation; + return FT_THROW( Invalid_Stream_Operation ); FT_MEM_COPY( zip->input, stream->base + stream->pos, size ); } @@ -383,7 +396,7 @@ zstream->next_in = zip->input; zstream->avail_in = size; - return Gzip_Err_Ok; + return FT_Err_Ok; } @@ -391,7 +404,7 @@ ft_gzip_file_fill_output( FT_GZipFile zip ) { z_stream* zstream = &zip->zstream; - FT_Error error = Gzip_Err_Ok; + FT_Error error = FT_Err_Ok; zip->cursor = zip->buffer; @@ -416,12 +429,12 @@ { zip->limit = zstream->next_out; if ( zip->limit == zip->cursor ) - error = Gzip_Err_Invalid_Stream_Operation; + error = FT_THROW( Invalid_Stream_Operation ); break; } else if ( err != Z_OK ) { - error = Gzip_Err_Invalid_Stream_Operation; + error = FT_THROW( Invalid_Stream_Operation ); break; } } @@ -435,7 +448,7 @@ ft_gzip_file_skip_output( FT_GZipFile zip, FT_ULong count ) { - FT_Error error = Gzip_Err_Ok; + FT_Error error = FT_Err_Ok; FT_ULong delta; @@ -583,15 +596,25 @@ } + /* documentation is in ftgzip.h */ + FT_EXPORT_DEF( FT_Error ) FT_Stream_OpenGzip( FT_Stream stream, FT_Stream source ) { FT_Error error; - FT_Memory memory = source->memory; + FT_Memory memory; FT_GZipFile zip = NULL; + if ( !stream || !source ) + { + error = FT_THROW( Invalid_Stream_Handle ); + goto Exit; + } + + memory = source->memory; + /* * check the header right now; this prevents allocating un-necessary * objects when we don't need them @@ -657,7 +680,7 @@ ft_gzip_file_io( zip, 0, NULL, 0 ); FT_FREE( zip_buff ); } - error = Gzip_Err_Ok; + error = FT_Err_Ok; } } @@ -671,7 +694,69 @@ return error; } -#else /* !FT_CONFIG_OPTION_USE_ZLIB */ + + /* documentation is in ftgzip.h */ + + FT_EXPORT_DEF( FT_Error ) + FT_Gzip_Uncompress( FT_Memory memory, + FT_Byte* output, + FT_ULong* output_len, + const FT_Byte* input, + FT_ULong input_len ) + { + z_stream stream; + int err; + + + /* check for `input' delayed to `inflate' */ + + if ( !memory || ! output_len || !output ) + return FT_THROW( Invalid_Argument ); + + /* this function is modeled after zlib's `uncompress' function */ + + stream.next_in = (Bytef*)input; + stream.avail_in = (uInt)input_len; + + stream.next_out = output; + stream.avail_out = (uInt)*output_len; + + stream.zalloc = (alloc_func)ft_gzip_alloc; + stream.zfree = (free_func) ft_gzip_free; + stream.opaque = memory; + + err = inflateInit2( &stream, MAX_WBITS ); + if ( err != Z_OK ) + return FT_THROW( Invalid_Argument ); + + err = inflate( &stream, Z_FINISH ); + if ( err != Z_STREAM_END ) + { + inflateEnd( &stream ); + if ( err == Z_OK ) + err = Z_BUF_ERROR; + } + else + { + *output_len = stream.total_out; + + err = inflateEnd( &stream ); + } + + if ( err == Z_MEM_ERROR ) + return FT_THROW( Out_Of_Memory ); + + if ( err == Z_BUF_ERROR ) + return FT_THROW( Array_Too_Large ); + + if ( err == Z_DATA_ERROR ) + return FT_THROW( Invalid_Table ); + + return FT_Err_Ok; + } + + +#else /* !FT_CONFIG_OPTION_USE_ZLIB */ FT_EXPORT_DEF( FT_Error ) FT_Stream_OpenGzip( FT_Stream stream, @@ -680,7 +765,24 @@ FT_UNUSED( stream ); FT_UNUSED( source ); - return Gzip_Err_Unimplemented_Feature; + return FT_THROW( Unimplemented_Feature ); + } + + + FT_EXPORT_DEF( FT_Error ) + FT_Gzip_Uncompress( FT_Memory memory, + FT_Byte* output, + FT_ULong* output_len, + const FT_Byte* input, + FT_ULong input_len ) + { + FT_UNUSED( memory ); + FT_UNUSED( output ); + FT_UNUSED( output_len ); + FT_UNUSED( input ); + FT_UNUSED( input_len ); + + return FT_THROW( Unimplemented_Feature ); } #endif /* !FT_CONFIG_OPTION_USE_ZLIB */