From 019d2f1dd9559de8ec9597000133c588e3cfd2ad Mon Sep 17 00:00:00 2001 From: "David G. Holm" Date: Sat, 6 Nov 1999 04:46:03 +0000 Subject: [PATCH] See ChangeLog entry 19991105-23:30 EDT David G. Holm --- harbour/ChangeLog | 5 +++++ harbour/source/rtl/filesys.c | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index e6756ea71b..b9223cf209 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,8 @@ +19991105-23:30 EDT David G. Holm + + * source/rtl/filesys.c + ! Only truncate the file when the size of the write is zero bytes. + 19991105-21:20 EDT David G. Holm * config/os2/icc.cf diff --git a/harbour/source/rtl/filesys.c b/harbour/source/rtl/filesys.c index 2656f9d0b3..3b9b04274e 100644 --- a/harbour/source/rtl/filesys.c +++ b/harbour/source/rtl/filesys.c @@ -535,16 +535,16 @@ USHORT hb_fsRead( FHANDLE hFileHandle, BYTE * pBuff, USHORT uiCount ) USHORT hb_fsWrite( FHANDLE hFileHandle, BYTE * pBuff, USHORT uiCount ) { - USHORT uiWritten; + USHORT uiWritten = 0; HB_TRACE(HB_TR_DEBUG, ("hb_fsWrite(%p, %p, %hu)", hFileHandle, pBuff, uiCount)); #if defined(HAVE_POSIX_IO) || defined(_MSC_VER) || defined(__MINGW32__) errno = 0; - uiWritten = write( hFileHandle, pBuff, uiCount ); + if( uiCount ) uiWritten = write( hFileHandle, pBuff, uiCount ); + else ftruncate( hFileHandle, tell( hFileHandle ) ); s_uiErrorLast = errno; - ftruncate( hFileHandle, tell( hFileHandle ) ); if( uiWritten == ( USHORT ) -1 ) uiWritten = 0; @@ -622,7 +622,7 @@ ULONG hb_fsWriteLarge( FHANDLE hFileHandle, BYTE * pBuff, ULONG ulCount ) #if defined(HAVE_POSIX_IO) || defined(_MSC_VER) || defined(__MINGW32__) errno = 0; - while( ulLeftToWrite ) + if( ulCount ) while( ulLeftToWrite ) { /* Determine how much to write this time */ if( ulLeftToWrite > ( ULONG ) INT_MAX ) @@ -645,8 +645,8 @@ ULONG hb_fsWriteLarge( FHANDLE hFileHandle, BYTE * pBuff, ULONG ulCount ) ulWritten += ( ULONG ) uiWritten; pPtr += uiWritten; } + else ftruncate( hFileHandle, tell( hFileHandle ) ); s_uiErrorLast = errno; - ftruncate( hFileHandle, tell( hFileHandle ) ); #else