2015-08-31 23:43 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* contrib/hbmzip/mzip.c
* contrib/hbnetio/netiocli.c
* contrib/hbnetio/netiosrv.c
* contrib/hbwin/win_prn2.c
* contrib/xhb/xhbcopyf.c
* src/rdd/dbffpt/dbffpt1.c
* src/rdd/dbfnsx/dbfnsx1.c
* src/rdd/delim1.c
* src/rdd/hbsix/sxcompr.c
* src/rdd/sdf1.c
* src/rtl/copyfile.c
* src/rtl/filesys.c
* src/rtl/fscopy.c
* src/rtl/hbmd5.c
* src/rtl/memofile.c
* src/rtl/philes.c
* src/rtl/vfile.c
* updated for possible -1 result returned by hb_fileRead()/hb_fileWrite()
This commit is contained in:
@@ -739,13 +739,15 @@ static void hb_fptDestroyGCdata( LPMEMOGCTABLE pGCtable )
|
||||
*/
|
||||
static HB_ERRCODE hb_fptReadGCdata( FPTAREAP pArea, LPMEMOGCTABLE pGCtable )
|
||||
{
|
||||
HB_SIZE nRead;
|
||||
int i;
|
||||
|
||||
hb_fptDestroyGCdata( pGCtable );
|
||||
memset( &pGCtable->fptHeader, 0, sizeof( FPTHEADER ) );
|
||||
|
||||
if( hb_fileReadAt( pArea->pMemoFile, &pGCtable->fptHeader,
|
||||
sizeof( FPTHEADER ), 0 ) >= 512 )
|
||||
nRead = hb_fileReadAt( pArea->pMemoFile, &pGCtable->fptHeader,
|
||||
sizeof( FPTHEADER ), 0 );
|
||||
if( nRead >= 512 && nRead != ( HB_SIZE ) FS_ERROR )
|
||||
{
|
||||
if( pArea->bMemoType == DB_MEMO_SMT || pArea->bMemoType == DB_MEMO_DBT )
|
||||
pGCtable->ulNextBlock = HB_GET_LE_UINT32( pGCtable->fptHeader.nextBlock );
|
||||
@@ -999,20 +1001,20 @@ static HB_ULONG hb_fptGetMemoLen( FPTAREAP pArea, HB_USHORT uiIndex )
|
||||
if( pArea->bMemoType == DB_MEMO_DBT )
|
||||
{
|
||||
HB_BYTE pBlock[ DBT_DEFBLOCKSIZE ];
|
||||
HB_SIZE ulLen, u;
|
||||
HB_SIZE nLen, n;
|
||||
|
||||
do
|
||||
{
|
||||
ulLen = hb_fileReadAt( pArea->pMemoFile, pBlock, DBT_DEFBLOCKSIZE, fOffset );
|
||||
fOffset += ulLen;
|
||||
if( ulLen == 0 )
|
||||
nLen = hb_fileReadAt( pArea->pMemoFile, pBlock, DBT_DEFBLOCKSIZE, fOffset );
|
||||
if( nLen == 0 || nLen == ( HB_SIZE ) FS_ERROR )
|
||||
break;
|
||||
u = 0;
|
||||
while( u < ulLen && pBlock[ u ] != 0x1A )
|
||||
u++;
|
||||
ulSize += ( HB_ULONGCAST ) u;
|
||||
fOffset += nLen;
|
||||
n = 0;
|
||||
while( n < nLen && pBlock[ n ] != 0x1A )
|
||||
n++;
|
||||
ulSize += ( HB_ULONGCAST ) n;
|
||||
}
|
||||
while( u == DBT_DEFBLOCKSIZE );
|
||||
while( n == DBT_DEFBLOCKSIZE );
|
||||
}
|
||||
else if( hb_fileReadAt( pArea->pMemoFile, &fptBlock,
|
||||
sizeof( FPTBLOCK ), fOffset ) ==
|
||||
@@ -2482,23 +2484,23 @@ static HB_ERRCODE hb_fptCopyToRawFile( PHB_FILE pSrc, HB_FOFFSET from,
|
||||
if( size )
|
||||
{
|
||||
HB_FOFFSET written = 0;
|
||||
HB_ULONG ulBufSize, ulRead;
|
||||
HB_SIZE nBufSize;
|
||||
HB_BYTE * pBuffer;
|
||||
|
||||
ulBufSize = ( HB_ULONG ) HB_MIN( 0x10000, size );
|
||||
pBuffer = ( HB_BYTE * ) hb_xgrab( ulBufSize );
|
||||
nBufSize = ( HB_SIZE ) HB_MIN( 0x10000, size );
|
||||
pBuffer = ( HB_BYTE * ) hb_xgrab( nBufSize );
|
||||
|
||||
do
|
||||
{
|
||||
ulRead = ( HB_ULONGCAST ) hb_fileReadAt( pSrc, pBuffer, ( HB_ULONG )
|
||||
HB_MIN( ( HB_FOFFSET ) ulBufSize, size - written ),
|
||||
from + written );
|
||||
if( ulRead == 0 )
|
||||
HB_SIZE nRead = hb_fileReadAt( pSrc, pBuffer, ( HB_SIZE )
|
||||
HB_MIN( ( HB_FOFFSET ) nBufSize, size - written ),
|
||||
from + written );
|
||||
if( nRead == 0 || nRead == ( HB_SIZE ) FS_ERROR )
|
||||
errCode = EDBF_READ;
|
||||
else if( hb_fileWrite( pDst, pBuffer, ulRead, -1 ) != ulRead )
|
||||
else if( hb_fileWrite( pDst, pBuffer, nRead, -1 ) != nRead )
|
||||
errCode = EDBF_WRITE;
|
||||
else
|
||||
written += ulRead;
|
||||
written += nRead;
|
||||
}
|
||||
while( errCode == HB_SUCCESS && written < size );
|
||||
|
||||
@@ -2517,24 +2519,24 @@ static HB_ERRCODE hb_fptCopyToFile( PHB_FILE pSrc, HB_FOFFSET from,
|
||||
if( size )
|
||||
{
|
||||
HB_FOFFSET written = 0;
|
||||
HB_ULONG ulBufSize, ulRead;
|
||||
HB_SIZE nBufSize;
|
||||
HB_BYTE * pBuffer;
|
||||
|
||||
ulBufSize = ( HB_ULONG ) HB_MIN( 0x10000, size );
|
||||
pBuffer = ( HB_BYTE * ) hb_xgrab( ulBufSize );
|
||||
nBufSize = ( HB_SIZE ) HB_MIN( 0x10000, size );
|
||||
pBuffer = ( HB_BYTE * ) hb_xgrab( nBufSize );
|
||||
|
||||
do
|
||||
{
|
||||
ulRead = ( HB_ULONGCAST ) hb_fileReadAt( pSrc, pBuffer, ( HB_ULONG )
|
||||
HB_MIN( ( HB_FOFFSET ) ulBufSize, size - written ),
|
||||
from + written );
|
||||
if( ulRead == 0 )
|
||||
HB_SIZE nRead = hb_fileReadAt( pSrc, pBuffer, ( HB_SIZE )
|
||||
HB_MIN( ( HB_FOFFSET ) nBufSize, size - written ),
|
||||
from + written );
|
||||
if( nRead == 0 || nRead == ( HB_SIZE ) FS_ERROR )
|
||||
errCode = EDBF_READ;
|
||||
else if( hb_fileWriteAt( pDst, pBuffer, ulRead,
|
||||
to + written ) != ulRead )
|
||||
else if( hb_fileWriteAt( pDst, pBuffer, nRead,
|
||||
to + written ) != nRead )
|
||||
errCode = EDBF_WRITE;
|
||||
else
|
||||
written += ulRead;
|
||||
written += nRead;
|
||||
}
|
||||
while( errCode == HB_SUCCESS && written < size );
|
||||
|
||||
@@ -2989,25 +2991,25 @@ static HB_ERRCODE hb_fptWriteMemo( FPTAREAP pArea, HB_ULONG ulBlock, HB_ULONG ul
|
||||
/* TODO: uiMode => BLOB_IMPORT_COMPRESS, BLOB_IMPORT_ENCRYPT */
|
||||
if( pFile != NULL )
|
||||
{
|
||||
HB_ULONG ulWritten = 0, ulRead, ulBufSize = HB_MIN( ( 1 << 16 ), ulLen );
|
||||
HB_BYTE * bBuffer = ( HB_BYTE * ) hb_xgrab( ulBufSize );
|
||||
HB_SIZE nWritten = 0, nBufSize = HB_MIN( ( 1 << 16 ), ulLen );
|
||||
HB_BYTE * bBuffer = ( HB_BYTE * ) hb_xgrab( nBufSize );
|
||||
|
||||
do
|
||||
{
|
||||
ulRead = ( HB_ULONGCAST ) hb_fileRead( pFile, bBuffer,
|
||||
HB_MIN( ulBufSize, ulLen - ulWritten ), -1 );
|
||||
if( ulRead == 0 )
|
||||
HB_SIZE nRead = hb_fileRead( pFile, bBuffer,
|
||||
HB_MIN( nBufSize, ulLen - nWritten ), -1 );
|
||||
if( nRead == 0 || nRead == ( HB_SIZE ) FS_ERROR )
|
||||
errCode = EDBF_READ;
|
||||
else if( hb_fileWriteAt( pArea->pMemoFile, bBuffer,
|
||||
ulRead, fOffset ) != ulRead )
|
||||
nRead, fOffset ) != nRead )
|
||||
errCode = EDBF_WRITE;
|
||||
else
|
||||
{
|
||||
ulWritten += ulRead;
|
||||
fOffset += ulRead;
|
||||
nWritten += nRead;
|
||||
fOffset += nRead;
|
||||
}
|
||||
}
|
||||
while( errCode == HB_SUCCESS && ulWritten < ulLen );
|
||||
while( errCode == HB_SUCCESS && nWritten < ulLen );
|
||||
|
||||
hb_xfree( bBuffer );
|
||||
}
|
||||
@@ -4329,8 +4331,9 @@ static HB_ERRCODE hb_fptOpenMemFile( FPTAREAP pArea, LPDBOPENINFO pOpenInfo )
|
||||
memset( &fptHeader, 0, sizeof( fptHeader ) );
|
||||
if( hb_fptFileLockSh( pArea, HB_TRUE ) )
|
||||
{
|
||||
if( hb_fileReadAt( pArea->pMemoFile, &fptHeader,
|
||||
sizeof( FPTHEADER ), 0 ) >= 512 )
|
||||
HB_SIZE nRead = hb_fileReadAt( pArea->pMemoFile, &fptHeader,
|
||||
sizeof( FPTHEADER ), 0 );
|
||||
if( nRead >= 512 && nRead != ( HB_SIZE ) FS_ERROR )
|
||||
{
|
||||
pArea->uiMemoVersion = DB_MEMOVER_STD;
|
||||
if( pArea->bMemoType == DB_MEMO_SMT )
|
||||
|
||||
@@ -1196,7 +1196,7 @@ static HB_BOOL hb_nsxBlockRead( LPNSXINDEX pIndex, HB_ULONG ulBlock, void * buff
|
||||
hb_errInternal( 9103, "hb_nsxBlockRead on not locked index file.", NULL, NULL );
|
||||
|
||||
if( hb_fileReadAt( pIndex->pFile, buffer, iSize,
|
||||
hb_nsxFileOffset( pIndex, ulBlock ) ) != ( HB_ULONG ) iSize )
|
||||
hb_nsxFileOffset( pIndex, ulBlock ) ) != ( HB_SIZE ) iSize )
|
||||
{
|
||||
hb_nsxErrorRT( pIndex->pArea, EG_READ, EDBF_READ,
|
||||
pIndex->IndexName, hb_fsError(), 0, NULL );
|
||||
@@ -1214,7 +1214,7 @@ static HB_BOOL hb_nsxBlockWrite( LPNSXINDEX pIndex, HB_ULONG ulBlock, const void
|
||||
hb_errInternal( 9102, "hb_nsxBlockWrite on not locked index file.", NULL, NULL );
|
||||
|
||||
if( hb_fileWriteAt( pIndex->pFile, buffer, iSize,
|
||||
hb_nsxFileOffset( pIndex, ulBlock ) ) != ( HB_ULONG ) iSize )
|
||||
hb_nsxFileOffset( pIndex, ulBlock ) ) != ( HB_SIZE ) iSize )
|
||||
{
|
||||
hb_nsxErrorRT( pIndex->pArea, EG_WRITE, EDBF_WRITE,
|
||||
pIndex->IndexName, hb_fsError(), 0, NULL );
|
||||
@@ -5097,12 +5097,10 @@ static void hb_nsxSortSortPage( LPNSXSORTINFO pSort )
|
||||
|
||||
static void hb_nsxSortBufferFlush( LPNSXSORTINFO pSort )
|
||||
{
|
||||
HB_SIZE nSize;
|
||||
|
||||
if( pSort->ulPagesIO )
|
||||
{
|
||||
LPNSXINDEX pIndex = pSort->pTag->pIndex;
|
||||
nSize = ( HB_SIZE ) pSort->ulPagesIO * NSX_PAGELEN;
|
||||
HB_SIZE nSize = ( HB_SIZE ) pSort->ulPagesIO * NSX_PAGELEN;
|
||||
if( hb_fileWriteAt( pIndex->pFile, pSort->pBuffIO, nSize,
|
||||
hb_nsxFileOffset( pIndex, pSort->ulFirstIO ) ) != nSize )
|
||||
{
|
||||
|
||||
@@ -207,6 +207,8 @@ static int hb_delimNextChar( DELIMAREAP pArea )
|
||||
pArea->pBuffer + nLeft,
|
||||
pArea->nBufferSize - nLeft,
|
||||
pArea->nBufferStart + nLeft );
|
||||
if( pArea->nBufferRead == ( HB_SIZE ) FS_ERROR )
|
||||
pArea->nBufferRead = 0;
|
||||
if( pArea->nBufferRead > 0 &&
|
||||
pArea->pBuffer[ pArea->nBufferRead + nLeft - 1 ] == '\032' )
|
||||
pArea->nBufferRead--;
|
||||
|
||||
@@ -289,6 +289,8 @@ static int hb_LZSSxRead( PHB_LZSSX_COMPR pCompr )
|
||||
{
|
||||
pCompr->inBuffRead = hb_fileRead( pCompr->pInput, pCompr->inBuffer,
|
||||
pCompr->inBuffSize, -1 );
|
||||
if( pCompr->inBuffRead == ( HB_SIZE ) FS_ERROR )
|
||||
pCompr->inBuffRead = 0;
|
||||
pCompr->inBuffPos = 0;
|
||||
if( pCompr->inBuffPos < pCompr->inBuffRead )
|
||||
return ( HB_UCHAR ) pCompr->inBuffer[ pCompr->inBuffPos++ ];
|
||||
|
||||
@@ -97,12 +97,14 @@ static void hb_sdfClearRecordBuffer( SDFAREAP pArea )
|
||||
static HB_ERRCODE hb_sdfReadRecord( SDFAREAP pArea )
|
||||
{
|
||||
HB_USHORT uiRead, uiToRead, uiEolPos;
|
||||
HB_SIZE nRead;
|
||||
|
||||
HB_TRACE( HB_TR_DEBUG, ( "hb_sdfReadRecord(%p)", pArea ) );
|
||||
|
||||
uiToRead = pArea->uiRecordLen + pArea->uiEolLen + 2;
|
||||
uiRead = ( HB_USHORT ) hb_fileReadAt( pArea->pFile, pArea->pRecord, uiToRead,
|
||||
pArea->nRecordOffset );
|
||||
nRead = hb_fileReadAt( pArea->pFile, pArea->pRecord, uiToRead,
|
||||
pArea->nRecordOffset );
|
||||
uiRead = ( HB_USHORT ) ( nRead == ( HB_SIZE ) FS_ERROR ? 0 : nRead );
|
||||
if( uiRead > 0 && uiRead < uiToRead && pArea->pRecord[ uiRead - 1 ] == '\032' )
|
||||
--uiRead;
|
||||
|
||||
@@ -166,8 +168,9 @@ static HB_ERRCODE hb_sdfNextRecord( SDFAREAP pArea )
|
||||
|
||||
do
|
||||
{
|
||||
uiRead = ( HB_USHORT ) hb_fileReadAt( pArea->pFile, pArea->pRecord + uiRest,
|
||||
uiToRead - uiRest, ulOffset + uiRest ) + uiRest;
|
||||
HB_SIZE nRead = hb_fileReadAt( pArea->pFile, pArea->pRecord + uiRest,
|
||||
uiToRead - uiRest, ulOffset + uiRest ) + uiRest;
|
||||
uiRead = ( HB_USHORT ) ( nRead == ( HB_SIZE ) FS_ERROR ? 0 : nRead );
|
||||
if( uiRead > 0 && uiRead < uiToRead &&
|
||||
pArea->pRecord[ uiRead - 1 ] == '\032' )
|
||||
--uiRead;
|
||||
|
||||
Reference in New Issue
Block a user