bool WRCopyResFromFileToFile( WResFileID src_fid, uint_32 offset, uint_32 length, WResFileID dst_fid ) { uint_32 size; uint_8 *buf; bool ok; size = 0; buf = NULL; ok = (src_fid != WRES_NIL_HANDLE && dst_fid != WRES_NIL_HANDLE); ok = (ok && (buf = (uint_8 *)MemAlloc( CHUNK_SIZE )) != NULL); ok = (ok && RESSEEK( src_fid, offset, SEEK_SET ) != -1); while( ok && length - size > CHUNK_SIZE ) { ok = ok && WRReadResData( src_fid, (BYTE *)buf, CHUNK_SIZE ); ok = ok && WRWriteResData( dst_fid, (BYTE *)buf, CHUNK_SIZE ); size += CHUNK_SIZE; } ok = ok && WRReadResData( src_fid, (BYTE *)buf, length - size ); ok = ok && WRWriteResData( dst_fid, (BYTE *)buf, length - size ); if( buf != NULL ) { MemFree( buf ); } return( ok ); }
void * WRAPI WRLoadResData( char *file, uint_32 offset, uint_32 length ) { void *data; WResFileID handle; int ok; data = NULL; handle = -1; ok = (file != NULL && length != 0); if( ok ) { ok = ((data = WRMemAlloc( length )) != NULL); } if( ok ) { ok = ((handle = ResOpenFileRO( file )) != -1); } if( ok ) { ok = ((ResSeek( handle, offset, SEEK_SET )) != -1); } if( ok ) { ok = WRReadResData( handle, (BYTE *)data, length ); } if( handle != -1 ) { ResCloseFile( handle ); } if( !ok ) { if( data != NULL ) { WRMemFree( data ); data = NULL; } } return( data ); }