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:
Przemysław Czerpak
2015-08-31 23:43:30 +02:00
parent b6ddc55575
commit db3fe4b8d4
18 changed files with 137 additions and 85 deletions

View File

@@ -10,6 +10,26 @@
* Change, ! Fix, % Optimization, + Addition, - Removal, ; Comment
*/
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()
2015-08-31 16:49 UTC+0200 Przemyslaw Czerpak (druzus/at/poczta.onet.pl)
* include/harbour.hbx
+ added hb_socketAutoShutdown()

View File

@@ -689,7 +689,7 @@ static HB_BOOL hb_zipGetFileInfoFromHandle( PHB_FILE pFile, HB_U32 * pulCRC, HB_
do
{
nRead = hb_fileRead( pFile, pString, HB_Z_IOBUF_SIZE, -1 );
if( nRead > 0 )
if( nRead > 0 && nRead != ( HB_SIZE ) FS_ERROR )
{
ulCRC = crc32( ulCRC, pString, ( uInt ) nRead );
if( fText )
@@ -1043,7 +1043,8 @@ static int hb_zipStoreFile( zipFile hZip, int iParamFileName, int iParamZipName,
if( iResult == 0 )
{
pString = ( char * ) hb_xgrab( HB_Z_IOBUF_SIZE );
while( ( nLen = hb_fileRead( pFile, pString, HB_Z_IOBUF_SIZE, -1 ) ) > 0 )
while( ( nLen = hb_fileRead( pFile, pString, HB_Z_IOBUF_SIZE, -1 ) ) > 0 &&
nLen != ( HB_SIZE ) FS_ERROR )
zipWriteInFileInZip( hZip, pString, ( unsigned ) nLen );
hb_xfree( pString );
@@ -1149,7 +1150,8 @@ static int hb_zipStoreFileHandle( zipFile hZip, PHB_FILE pFile, int iParamZipNam
{
char * pString = ( char * ) hb_xgrab( HB_Z_IOBUF_SIZE );
hb_fileSeek( pFile, 0, FS_SET );
while( ( nLen = hb_fileRead( pFile, pString, HB_Z_IOBUF_SIZE, -1 ) ) > 0 )
while( ( nLen = hb_fileRead( pFile, pString, HB_Z_IOBUF_SIZE, -1 ) ) > 0 &&
nLen != ( HB_SIZE ) FS_ERROR )
zipWriteInFileInZip( hZip, pString, ( unsigned ) nLen );
hb_xfree( pString );
@@ -1266,7 +1268,8 @@ static int hb_unzipExtractCurrentFile( unzFile hUnzip, const char * szFileName,
pString = ( char * ) hb_xgrab( HB_Z_IOBUF_SIZE );
while( ( iResult = unzReadCurrentFile( hUnzip, pString, HB_Z_IOBUF_SIZE ) ) > 0 )
hb_fileWrite( pFile, pString, ( HB_SIZE ) iResult, -1 );
if( hb_fileWrite( pFile, pString, ( HB_SIZE ) iResult, -1 ) != ( HB_SIZE ) iResult )
break;
hb_xfree( pString );
@@ -1458,7 +1461,8 @@ static int hb_unzipExtractCurrentFileToHandle( unzFile hUnzip, PHB_FILE pFile, c
char * pString = ( char * ) hb_xgrab( HB_Z_IOBUF_SIZE );
while( ( iResult = unzReadCurrentFile( hUnzip, pString, HB_Z_IOBUF_SIZE ) ) > 0 )
hb_fileWrite( pFile, pString, ( HB_SIZE ) iResult, -1 );
if( hb_fileWrite( pFile, pString, ( HB_SIZE ) iResult, -1 ) != ( HB_SIZE ) iResult )
break;
hb_xfree( pString );

View File

@@ -2206,7 +2206,7 @@ static HB_SIZE s_fileRead( PHB_FILE pFile, void * data, HB_SIZE ulSize,
{
HB_ERRCODE errCode = ( HB_ERRCODE ) HB_GET_LE_UINT32( &msgbuf[ 8 ] );
ulResult = HB_GET_LE_UINT32( &msgbuf[ 4 ] );
if( ulResult > 0 )
if( ulResult > 0 && ulResult != ( HB_SIZE ) FS_ERROR )
{
if( ulResult > ulSize ) /* error, it should not happen, enemy attack? */
{
@@ -2274,7 +2274,7 @@ static HB_SIZE s_fileReadAt( PHB_FILE pFile, void * data, HB_SIZE ulSize,
{
HB_ERRCODE errCode = ( HB_ERRCODE ) HB_GET_LE_UINT32( &msgbuf[ 8 ] );
ulResult = HB_GET_LE_UINT32( &msgbuf[ 4 ] );
if( ulResult > 0 )
if( ulResult > 0 && ulResult != ( HB_SIZE ) FS_ERROR )
{
if( ulResult > ulSize ) /* error, it should not happen, enemy attack? */
{

View File

@@ -1230,6 +1230,8 @@ HB_FUNC( NETIO_SERVER )
HB_PUT_LE_UINT32( &msg[ 4 ], len );
HB_PUT_LE_UINT32( &msg[ 8 ], errFsCode );
memset( msg + 12, '\0', NETIO_MSGLEN - 12 );
if( len == ( HB_SIZE ) FS_ERROR )
len = 0;
}
}
break;

View File

@@ -394,7 +394,8 @@ HB_FUNC( WIN_PRINTFILERAW )
HB_SIZE nRead;
nResult = 1;
while( ( nRead = hb_fileRead( pFile, pbyBuffer, HB_PRINT_BUFFER_SIZE, -1 ) ) > 0 )
while( ( nRead = hb_fileRead( pFile, pbyBuffer, HB_PRINT_BUFFER_SIZE, -1 ) ) > 0 &&
nRead != ( HB_SIZE ) FS_ERROR )
{
HB_SIZE nWritten = 0;

View File

@@ -124,13 +124,16 @@ static HB_BOOL hb_copyfile( const char * pszSource, const char * pszDest, PHB_IT
if( pBlock && HB_IS_EVALITEM( pBlock ) )
pCount = hb_itemNew( NULL );
while( ( nRead = hb_fileRead( pSource, buffer, BUFFER_SIZE, -1 ) ) != 0 )
while( ( nRead = hb_fileRead( pSource, buffer, BUFFER_SIZE, -1 ) ) != 0 &&
nRead != ( HB_SIZE ) FS_ERROR )
{
HB_SIZE nWritten = 0;
while( nWritten < nRead )
{
nWritten += hb_fileWrite( pDest, buffer + nWritten, nRead - nWritten, -1 );
HB_SIZE nDone = hb_fileWrite( pDest, buffer + nWritten, nRead - nWritten, -1 );
if( nDone != ( HB_SIZE ) FS_ERROR )
nWritten += nDone;
if( nWritten < nRead )
{
pError = hb_errRT_FileError( pError, NULL, EG_WRITE, 2016, pszDest );

View File

@@ -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 )

View File

@@ -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 )
{

View File

@@ -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--;

View File

@@ -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++ ];

View File

@@ -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;

View File

@@ -124,13 +124,16 @@ static HB_BOOL hb_copyfile( const char * pszSource, const char * pszDest )
buffer = ( HB_UCHAR * ) hb_xgrab( BUFFER_SIZE );
bRetVal = HB_TRUE;
while( ( nRead = hb_fileRead( pSource, buffer, BUFFER_SIZE, -1 ) ) != 0 )
while( ( nRead = hb_fileRead( pSource, buffer, BUFFER_SIZE, -1 ) ) != 0 &&
nRead != ( HB_SIZE ) FS_ERROR )
{
HB_SIZE nWritten = 0;
while( nWritten < nRead )
{
nWritten += hb_fileWrite( pDest, buffer + nWritten, nRead - nWritten, -1 );
HB_SIZE nDone = hb_fileWrite( pDest, buffer + nWritten, nRead - nWritten, -1 );
if( nDone > 0 )
nWritten += nDone;
if( nWritten < nRead )
{
pError = hb_errRT_FileError( pError, NULL, EG_WRITE, 2016, pszDest );

View File

@@ -942,7 +942,7 @@ HB_SIZE hb_fsPipeIsData( HB_FHANDLE hPipeHandle, HB_SIZE nBufferSize,
hb_vmRequestQuery() == 0 );
if( ! fResult )
nToRead = ( HB_SIZE ) -1;
nToRead = ( HB_SIZE ) FS_ERROR;
else if( dwAvail > 0 )
nToRead = ( ( HB_SIZE ) dwAvail < nBufferSize ) ? dwAvail : nBufferSize;
}
@@ -972,7 +972,7 @@ HB_SIZE hb_fsPipeIsData( HB_FHANDLE hPipeHandle, HB_SIZE nBufferSize,
hb_vmRequestQuery() == 0 );
if( ! fResult )
nToRead = ( HB_SIZE ) -1;
nToRead = ( HB_SIZE ) FS_ERROR;
else if( avail.cbpipe > 0 )
nToRead = ( ( HB_SIZE ) avail.cbpipe < nBufferSize ) ? avail.cbpipe :
nBufferSize;
@@ -1055,11 +1055,11 @@ HB_SIZE hb_fsPipeRead( HB_FHANDLE hPipeHandle, void * buffer, HB_SIZE nSize,
HB_TRACE( HB_TR_DEBUG, ( "hb_fsPipeRead(%p,%p,%" HB_PFS "u,%" PFHL "d)", ( void * ) ( HB_PTRDIFF ) hPipeHandle, buffer, nSize, nTimeOut ) );
nRead = hb_fsPipeIsData( hPipeHandle, nSize, nTimeOut );
if( nRead != ( HB_SIZE ) -1 && nRead > 0 )
if( nRead != ( HB_SIZE ) FS_ERROR && nRead > 0 )
{
nRead = hb_fsReadLarge( hPipeHandle, buffer, nRead );
if( nRead == 0 )
nRead = ( HB_SIZE ) -1;
nRead = ( HB_SIZE ) FS_ERROR;
}
return nRead;
@@ -1098,7 +1098,7 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi
hb_releaseCPU();
fResult = WriteFile( hPipe, buffer, ( DWORD ) nSize, &dwWritten, NULL ) != 0;
nWritten = fResult ? ( HB_SIZE ) dwWritten : ( HB_SIZE ) -1;
nWritten = fResult ? ( HB_SIZE ) dwWritten : ( HB_SIZE ) FS_ERROR;
hb_fsSetIOError( fResult, 0 );
}
while( fResult && nWritten == 0 &&
@@ -1112,7 +1112,7 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi
else
{
hb_fsSetIOError( HB_FALSE, 0 );
nWritten = ( HB_SIZE ) -1;
nWritten = ( HB_SIZE ) FS_ERROR;
}
}
#elif defined( HB_OS_OS2 )
@@ -1136,7 +1136,7 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi
fResult = DosWrite( ( HPIPE ) hPipeHandle, ( PVOID ) buffer,
( ULONG ) nSize, &cbActual ) == NO_ERROR;
nWritten = fResult ? ( HB_SIZE ) cbActual : ( HB_SIZE ) -1;
nWritten = fResult ? ( HB_SIZE ) cbActual : ( HB_SIZE ) FS_ERROR;
hb_fsSetIOError( fResult, 0 );
}
while( fResult && nWritten == 0 &&
@@ -1150,7 +1150,7 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi
else
{
hb_fsSetIOError( HB_FALSE, 0 );
nWritten = ( HB_SIZE ) -1;
nWritten = ( HB_SIZE ) FS_ERROR;
}
}
#elif defined( HB_OS_UNIX ) && ! defined( HB_OS_SYMBIAN )
@@ -1216,7 +1216,7 @@ HB_SIZE hb_fsPipeWrite( HB_FHANDLE hPipeHandle, const void * buffer, HB_SIZE nSi
if( iResult == -1 )
{
hb_fsSetIOError( HB_FALSE, 0 );
nWritten = ( HB_SIZE ) -1;
nWritten = ( HB_SIZE ) FS_ERROR;
}
else
nWritten = hb_fsWriteLarge( hPipeHandle, buffer, nSize );

View File

@@ -72,7 +72,8 @@ HB_BOOL hb_fsCopy( const char * pszSource, const char * pszDest )
for( ;; )
{
if( ( nBytesRead = hb_fileRead( pSrcFile, pbyBuffer, HB_FSCOPY_BUFFERSIZE, -1 ) ) > 0 )
if( ( nBytesRead = hb_fileRead( pSrcFile, pbyBuffer, HB_FSCOPY_BUFFERSIZE, -1 ) ) > 0 &&
nBytesRead != ( HB_SIZE ) FS_ERROR )
{
if( nBytesRead != hb_fileWrite( pDstFile, pbyBuffer, nBytesRead, -1 ) )
{
@@ -84,7 +85,7 @@ HB_BOOL hb_fsCopy( const char * pszSource, const char * pszDest )
else
{
errCode = hb_fsError();
bRetVal = ( errCode == 0 );
bRetVal = ( errCode == 0 && nBytesRead != ( HB_SIZE ) FS_ERROR );
break;
}
}

View File

@@ -309,6 +309,8 @@ HB_BOOL hb_md5file( const char * pszFileName, char * digest )
hb_md5accinit( md5.accum );
n = hb_fileRead( pFile, readbuf, MAX_FBUF, -1 );
if( n == ( HB_SIZE ) FS_ERROR )
n = 0;
flen += n;
while( n == MAX_FBUF )
{
@@ -318,6 +320,8 @@ HB_BOOL hb_md5file( const char * pszFileName, char * digest )
hb_md5go( &md5 );
}
n = hb_fileRead( pFile, readbuf, MAX_FBUF, -1 );
if( n == ( HB_SIZE ) FS_ERROR )
n = 0;
flen += n;
}
hb_fileClose( pFile );

View File

@@ -74,6 +74,8 @@ static void hb_memoread( HB_BOOL bHandleEOF )
char * pbyBuffer = ( char * ) hb_xgrab( nSize + 1 );
nSize = hb_fileReadAt( pFile, pbyBuffer, nSize, 0 );
if( nSize == ( HB_SIZE ) FS_ERROR )
nSize = 0;
/* Don't read the file terminating EOF character */
if( bHandleEOF && nSize > 0 )

View File

@@ -549,8 +549,8 @@ HB_FUNC( HB_PREAD )
uiError = hb_fsError();
}
if( nSize == ( HB_SIZE ) -1 )
hb_retni( -1 );
if( nSize == ( HB_SIZE ) FS_ERROR )
hb_retni( FS_ERROR );
else
hb_retns( nSize );
hb_fsSetFError( uiError );
@@ -576,8 +576,12 @@ HB_FUNC( HB_PWRITE )
if( nWrite < nLen )
nLen = nWrite;
}
hb_retns( hb_fsPipeWrite( hPipe, data, nLen, hb_parnint( 4 ) ) );
nLen = hb_fsPipeWrite( hPipe, data, nLen, hb_parnint( 4 ) );
hb_fsSetFError( hb_fsError() );
if( nLen == ( HB_SIZE ) FS_ERROR )
hb_retni( FS_ERROR );
else
hb_retns( nLen );
}
else
hb_errRT_BASE_SubstR( EG_ARG, 4001, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );

View File

@@ -584,8 +584,8 @@ HB_FUNC( HB_VFREAD )
uiError = hb_fsError();
}
if( nRead == ( HB_SIZE ) -1 )
hb_retni( -1 );
if( nRead == ( HB_SIZE ) FS_ERROR )
hb_retni( FS_ERROR );
else
hb_retns( nRead );
hb_fsSetFError( uiError );
@@ -610,7 +610,7 @@ HB_FUNC( HB_VFREADLEN )
nRead = hb_fileRead( pFile, buffer, nToRead, hb_parnintdef( 3, -1 ) );
uiError = hb_fsError();
if( nRead == ( HB_SIZE ) -1 )
if( nRead == ( HB_SIZE ) FS_ERROR )
nRead = 0;
hb_retclen_buffer( buffer, nRead );
}
@@ -643,8 +643,8 @@ HB_FUNC( HB_VFWRITE )
nLen = hb_fileWrite( pFile, hb_parc( 2 ), nLen,
hb_parnintdef( 4, -1 ) );
if( nLen == ( HB_SIZE ) -1 )
hb_retni( -1 );
if( nLen == ( HB_SIZE ) FS_ERROR )
hb_retni( FS_ERROR );
else
hb_retns( nLen );
uiError = hb_fsError();
@@ -683,8 +683,8 @@ HB_FUNC( HB_VFREADAT )
uiError = hb_fsError();
}
if( nRead == ( HB_SIZE ) -1 )
hb_retni( -1 );
if( nRead == ( HB_SIZE ) FS_ERROR )
hb_retni( FS_ERROR );
else
hb_retns( nRead );
hb_fsSetFError( uiError );
@@ -714,8 +714,8 @@ HB_FUNC( HB_VFWRITEAT )
nLen = hb_fileWriteAt( pFile, pszData, nLen,
( HB_FOFFSET ) hb_parnintdef( 4, -1 ) );
if( nLen == ( HB_SIZE ) -1 )
hb_retni( -1 );
if( nLen == ( HB_SIZE ) FS_ERROR )
hb_retni( FS_ERROR );
else
hb_retns( nLen );
uiError = hb_fsError();