예제 #1
0
파일: ftgzip.c 프로젝트: bowlofstew/Aquaria
static FT_Error
ft_gzip_file_fill_input( FT_GZipFile  zip )
{
    z_stream*  zstream = &zip->zstream;
    FT_Stream  stream  = zip->source;
    FT_ULong   size;


    if ( stream->read )
    {
        size = stream->read( stream, stream->pos, zip->input,
                             FT_GZIP_BUFFER_SIZE );
        if ( size == 0 )
            return Gzip_Err_Invalid_Stream_Operation;
    }
    else
    {
        size = stream->size - stream->pos;
        if ( size > FT_GZIP_BUFFER_SIZE )
            size = FT_GZIP_BUFFER_SIZE;

        if ( size == 0 )
            return Gzip_Err_Invalid_Stream_Operation;

        FT_MEM_COPY( zip->input, stream->base + stream->pos, size );
    }
    stream->pos += size;

    zstream->next_in  = zip->input;
    zstream->avail_in = size;

    return Gzip_Err_Ok;
}
예제 #2
0
파일: ftbzip2.c 프로젝트: 03050903/Urho3D
  static FT_Error
  ft_bzip2_file_fill_input( FT_BZip2File  zip )
  {
    bz_stream*  bzstream = &zip->bzstream;
    FT_Stream   stream    = zip->source;
    FT_ULong    size;


    if ( stream->read )
    {
      size = stream->read( stream, stream->pos, zip->input,
                           FT_BZIP2_BUFFER_SIZE );
      if ( size == 0 )
        return FT_THROW( Invalid_Stream_Operation );
    }
    else
    {
      size = stream->size - stream->pos;
      if ( size > FT_BZIP2_BUFFER_SIZE )
        size = FT_BZIP2_BUFFER_SIZE;

      if ( size == 0 )
        return FT_THROW( Invalid_Stream_Operation );

      FT_MEM_COPY( zip->input, stream->base + stream->pos, size );
    }
    stream->pos += size;

    bzstream->next_in  = (char*)zip->input;
    bzstream->avail_in = size;

    return FT_Err_Ok;
  }
예제 #3
0
  FT_Stream_Seek( FT_Stream  stream,
                  FT_ULong   pos )
  {
    FT_Error  error = FT_Err_Ok;


    stream->pos = pos;

    if ( stream->read )
    {
      if ( stream->read( stream, pos, 0, 0 ) )
      {
        FT_ERROR(( "FT_Stream_Seek: invalid i/o; pos = 0x%lx, size = 0x%lx\n",
                   pos, stream->size ));

        error = FT_Err_Invalid_Stream_Operation;
      }
    }
    /* note that seeking to the first position after the file is valid */
    else if ( pos > stream->size )
    {
      FT_ERROR(( "FT_Stream_Seek: invalid i/o; pos = 0x%lx, size = 0x%lx\n",
                 pos, stream->size ));

      error = FT_Err_Invalid_Stream_Operation;
    }

    return error;
  }
예제 #4
0
  FT_Stream_ReadChar( FT_Stream  stream,
                      FT_Error*  error )
  {
    FT_Byte  result = 0;


    FT_ASSERT( stream );

    *error = FT_Err_Ok;

    if ( stream->read )
    {
      if ( stream->read( stream, stream->pos, &result, 1L ) != 1L )
        goto Fail;
    }
    else
    {
      if ( stream->pos < stream->size )
        result = stream->base[stream->pos];
      else
        goto Fail;
    }
    stream->pos++;

    return result;

  Fail:
    *error = FT_Err_Invalid_Stream_Operation;
    FT_ERROR(( "FT_Stream_ReadChar: invalid i/o; pos = 0x%lx, size = 0x%lx\n",
               stream->pos, stream->size ));

    return 0;
  }
예제 #5
0
  FT_Stream_TryRead( FT_Stream  stream,
                     FT_Byte*   buffer,
                     FT_ULong   count )
  {
    FT_ULong  read_bytes = 0;


    if ( stream->pos >= stream->size )
      goto Exit;

    if ( stream->read )
      read_bytes = stream->read( stream, stream->pos, buffer, count );
    else
    {
      read_bytes = stream->size - stream->pos;
      if ( read_bytes > count )
        read_bytes = count;

      FT_MEM_COPY( buffer, stream->base + stream->pos, read_bytes );
    }

    stream->pos += read_bytes;

  Exit:
    return read_bytes;
  }
예제 #6
0
  FT_Stream_EnterFrame( FT_Stream  stream,
                        FT_ULong   count )
  {
    FT_Error  error = FT_Err_Ok;
    FT_ULong  read_bytes;


    /* check for nested frame access */
    FT_ASSERT( stream && stream->cursor == 0 );

    if ( stream->read )
    {
      /* allocate the frame in memory */
      FT_Memory  memory = stream->memory;


      if ( FT_QALLOC( stream->base, count ) )
        goto Exit;

      /* read it */
      read_bytes = stream->read( stream, stream->pos,
                                 stream->base, count );
      if ( read_bytes < count )
      {
        FT_ERROR(( "FT_Stream_EnterFrame:" ));
        FT_ERROR(( " invalid read; expected %lu bytes, got %lu\n",
                   count, read_bytes ));

        FT_FREE( stream->base );
        error = FT_Err_Invalid_Stream_Operation;
      }
      stream->cursor = stream->base;
      stream->limit  = stream->cursor + count;
      stream->pos   += read_bytes;
    }
    else
    {
      /* check current and new position */
      if ( stream->pos >= stream->size        ||
           stream->pos + count > stream->size )
      {
        FT_ERROR(( "FT_Stream_EnterFrame:" ));
        FT_ERROR(( " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n",
                   stream->pos, count, stream->size ));

        error = FT_Err_Invalid_Stream_Operation;
        goto Exit;
      }

      /* set cursor */
      stream->cursor = stream->base + stream->pos;
      stream->limit  = stream->cursor + count;
      stream->pos   += count;
    }

  Exit:
    return error;
  }
예제 #7
0
파일: ftstream.c 프로젝트: Justasic/RTCW-SP
BASE_FUNC(FT_Long)  FT_Read_LongLE(FT_Stream stream,
                                   FT_Error   *error)
{
    FT_Byte reads[4];
    FT_Byte  *p = 0;
    FT_Long result = 0;


    FT_Assert(stream);

    *error = FT_Err_Ok;

    if(stream->pos + 3 < stream->size)
    {
        if(stream->read)
        {
            if(stream->read(stream, stream->pos, reads, 4L) != 4L)
            {
                goto Fail;
            }

            p = reads;
        }
        else
        {
            p = stream->base + stream->pos;
        }

        if(p)
        {
            result = NEXT_LongLE(p);
        }
    }
    else
    {
        goto Fail;
    }

    stream->pos += 4;

    return result;

Fail:
    FT_ERROR(("FT_Read_Long:"));
    FT_ERROR((" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
              stream->pos, stream->size));
    *error = FT_Err_Invalid_Stream_Operation;

    return 0;
}
예제 #8
0
파일: ftstream.c 프로젝트: Justasic/RTCW-SP
BASE_FUNC(FT_Short)  FT_Read_Short(FT_Stream stream,
                                   FT_Error   *error)
{
    FT_Byte reads[2];
    FT_Byte  *p = 0;
    FT_Short result = 0;


    FT_Assert(stream);

    *error = FT_Err_Ok;

    if(stream->pos + 1 < stream->size)
    {
        if(stream->read)
        {
            if(stream->read(stream, stream->pos, reads, 2L) != 2L)
            {
                goto Fail;
            }

            p = reads;
        }
        else
        {
            p = stream->base + stream->pos;
        }

        if(p)
        {
            result = NEXT_Short(p);
        }
    }
    else
    {
        goto Fail;
    }

    stream->pos += 2;

    return result;

Fail:
    *error = FT_Err_Invalid_Stream_Operation;
    FT_ERROR(("FT_Read_Short:"));
    FT_ERROR((" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
              stream->pos, stream->size));

    return 0;
}
예제 #9
0
파일: ftstream.c 프로젝트: Justasic/RTCW-SP
BASE_FUNC(FT_Error)  FT_Read_Stream_At(FT_Stream stream,
                                       FT_ULong pos,
                                       FT_Byte    *buffer,
                                       FT_ULong count)
{
    FT_Error error = FT_Err_Ok;
    FT_ULong read_bytes;


    if(pos >= stream->size)
    {
        FT_ERROR(("FT_Read_Stream_At:"));
        FT_ERROR((" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
                  pos, stream->size));

        return FT_Err_Invalid_Stream_Operation;
    }

    if(stream->read)
    {
        read_bytes = stream->read(stream, pos, buffer, count);
    }
    else
    {
        read_bytes = stream->size - pos;

        if(read_bytes > count)
        {
            read_bytes = count;
        }

        MEM_Copy(buffer, stream->base + pos, read_bytes);
    }

    stream->pos = pos + read_bytes;

    if(read_bytes < count)
    {
        FT_ERROR(("FT_Read_Stream_At:"));
        FT_ERROR((" invalid read; expected %lu bytes, got %lu\n",
                  count, read_bytes));

        error = FT_Err_Invalid_Stream_Operation;
    }

    return error;
}
예제 #10
0
  FT_Stream_ReadLongLE( FT_Stream  stream,
                        FT_Error*  error )
  {
    FT_Byte   reads[4];
    FT_Byte*  p = 0;
    FT_Long   result = 0;


    FT_ASSERT( stream );

    *error = FT_Err_Ok;

    if ( stream->pos + 3 < stream->size )
    {
      if ( stream->read )
      {
        if ( stream->read( stream, stream->pos, reads, 4L ) != 4L )
          goto Fail;

        p = reads;
      }
      else
      {
        p = stream->base + stream->pos;
      }

      if ( p )
        result = FT_NEXT_LONG_LE( p );
    }
    else
      goto Fail;

    stream->pos += 4;

    return result;

  Fail:
    FT_ERROR(( "FT_Stream_ReadLongLE:" ));
    FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
               stream->pos, stream->size ));
    *error = FT_Err_Invalid_Stream_Operation;

    return 0;
  }
예제 #11
0
  FT_Stream_ReadOffset( FT_Stream  stream,
                        FT_Error*  error )
  {
    FT_Byte   reads[3];
    FT_Byte*  p = 0;
    FT_Long   result = 0;


    FT_ASSERT( stream );

    *error = FT_Err_Ok;

    if ( stream->pos + 2 < stream->size )
    {
      if ( stream->read )
      {
        if (stream->read( stream, stream->pos, reads, 3L ) != 3L )
          goto Fail;

        p = reads;
      }
      else
      {
        p = stream->base + stream->pos;
      }

      if ( p )
        result = FT_NEXT_OFF3( p );
    }
    else
      goto Fail;

    stream->pos += 3;

    return result;

  Fail:
    *error = FT_Err_Invalid_Stream_Operation;
    FT_ERROR(( "FT_Stream_ReadOffset:" ));
    FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
               stream->pos, stream->size ));

    return 0;
  }
예제 #12
0
  FT_Stream_ReadShortLE( FT_Stream  stream,
                         FT_Error*  error )
  {
    FT_Byte   reads[2];
    FT_Byte*  p = 0;
    FT_Short  result = 0;


    FT_ASSERT( stream );

    *error = FT_Err_Ok;

    if ( stream->pos + 1 < stream->size )
    {
      if ( stream->read )
      {
        if ( stream->read( stream, stream->pos, reads, 2L ) != 2L )
          goto Fail;

        p = reads;
      }
      else
      {
        p = stream->base + stream->pos;
      }

      if ( p )
        result = FT_NEXT_SHORT_LE( p );
    }
    else
      goto Fail;

    stream->pos += 2;

    return result;

  Fail:
    *error = FT_Err_Invalid_Stream_Operation;
    FT_ERROR(( "FT_Stream_ReadShortLE:" ));
    FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",
               stream->pos, stream->size ));

    return 0;
  }
예제 #13
0
파일: ftstream.c 프로젝트: Justasic/RTCW-SP
BASE_FUNC(FT_Char)  FT_Read_Char(FT_Stream stream,
                                 FT_Error   *error)
{
    FT_Byte result = 0;


    FT_Assert(stream);

    *error = FT_Err_Ok;

    if(stream->read)
    {
        if(stream->read(stream, stream->pos, &result, 1L) != 1L)
        {
            goto Fail;
        }
    }
    else
    {
        if(stream->pos < stream->size)
        {
            result = stream->base[stream->pos];
        }
        else
        {
            goto Fail;
        }
    }

    stream->pos++;

    return result;

Fail:
    *error = FT_Err_Invalid_Stream_Operation;
    FT_ERROR(("FT_Read_Char:"));
    FT_ERROR((" invalid i/o; pos = 0x%lx, size = 0x%lx\n",
              stream->pos, stream->size));

    return 0;
}
예제 #14
0
  FT_Stream_EnterFrame( FT_Stream  stream,
                        FT_ULong   count )
  {
    FT_Error  error = FT_Err_Ok;
    FT_ULong  read_bytes;


    /* check for nested frame access */
    FT_ASSERT( stream && stream->cursor == 0 );

    if ( stream->read )
    {
      /* allocate the frame in memory */
      FT_Memory  memory = stream->memory;

#ifdef FT_DEBUG_MEMORY
      /* assume _ft_debug_file and _ft_debug_lineno are already set */
      stream->base = (unsigned char*)ft_mem_qalloc( memory, count, &error );
      if ( error )
        goto Exit;
#else
      if ( FT_QALLOC( stream->base, count ) )
        goto Exit;
#endif
      /* read it */
      read_bytes = stream->read( stream, stream->pos,
                                 stream->base, count );
      if ( read_bytes < count )
      {
        FT_ERROR(( "FT_Stream_EnterFrame:" ));
        FT_ERROR(( " invalid read; expected %lu bytes, got %lu\n",
                   count, read_bytes ));

        FT_FREE( stream->base );
        error = FT_Err_Invalid_Stream_Operation;
      }
      stream->cursor = stream->base;
      stream->limit  = stream->cursor + count;
      stream->pos   += read_bytes;
    }
    else
    {
      /* check current and new position */
      if ( stream->pos >= stream->size        ||
           stream->pos + count > stream->size )
      {
        FT_ERROR(( "FT_Stream_EnterFrame:" ));
        FT_ERROR(( " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n",
                   stream->pos, count, stream->size ));

        error = FT_Err_Invalid_Stream_Operation;
        goto Exit;
      }

      /* set cursor */
      stream->cursor = stream->base + stream->pos;
      stream->limit  = stream->cursor + count;
      stream->pos   += count;
    }

  Exit:
    return error;
  }