static FT_ULong ft_lzw_file_io( FT_LZWFile zip, FT_ULong pos, FT_Byte* buffer, FT_ULong count ) { FT_ULong result = 0; FT_Error error; /* Teset inflate stream if we're seeking backwards. */ /* Yes, that is not too efficient, but it saves memory :-) */ if ( pos < zip->pos ) { error = ft_lzw_file_reset( zip ); if ( error ) goto Exit; } /* skip unwanted bytes */ if ( pos > zip->pos ) { error = ft_lzw_file_skip_output( zip, (FT_ULong)( pos - zip->pos ) ); if ( error ) goto Exit; } if ( count == 0 ) goto Exit; /* now read the data */ for (;;) { FT_ULong delta; delta = (FT_ULong)( zip->limit - zip->cursor ); if ( delta >= count ) delta = count; FT_MEM_COPY( buffer, zip->cursor, delta ); buffer += delta; result += delta; zip->cursor += delta; zip->pos += delta; count -= delta; if ( count == 0 ) break; error = ft_lzw_file_fill_output( zip ); if ( error ) break; } Exit: return result; }
static FT_ULong ft_lzw_file_io( FT_LZWFile zip, FT_ULong pos, FT_Byte* buffer, FT_ULong count ) { FT_ULong result = 0; FT_Error error; /* seeking backwards. */ if ( pos < zip->pos ) { /* If the new position is within the output buffer, simply */ /* decrement pointers, otherwise we reset the stream completely! */ if ( ( zip->pos - pos ) <= (FT_ULong)( zip->cursor - zip->buffer ) ) { zip->cursor -= zip->pos - pos; zip->pos = pos; } else { error = ft_lzw_file_reset( zip ); if ( error ) goto Exit; } } /* skip unwanted bytes */ if ( pos > zip->pos ) { error = ft_lzw_file_skip_output( zip, (FT_ULong)( pos - zip->pos ) ); if ( error ) goto Exit; } if ( count == 0 ) goto Exit; /* now read the data */ for (;;) { FT_ULong delta; delta = (FT_ULong)( zip->limit - zip->cursor ); if ( delta >= count ) delta = count; FT_MEM_COPY( buffer + result, zip->cursor, delta ); result += delta; zip->cursor += delta; zip->pos += delta; count -= delta; if ( count == 0 ) break; error = ft_lzw_file_fill_output( zip ); if ( error ) break; } Exit: return result; }