From 09c5c608bbacc0632aab2250484b39725f738e3b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 9 Apr 2012 19:33:27 +0000 Subject: [PATCH] 2012-04-09 21:33 UTC+0200 Viktor Szakats (harbour syenar.net) * src/rtl/fscopy.c + using hb_file*() API instead of hb_fs*() API. Completing TODO originating from: https://groups.google.com/d/msg/harbour-devel/0QY0SJ8HBFU/rWbUvJXygWYJ ; review me. I had to add an ugly-looking hack for win, because error 38 was returned when reaching the end of file successfully. with hb_fs*() API this didn't happen. --- harbour/ChangeLog | 9 +++++++++ harbour/src/rtl/fscopy.c | 31 +++++++++++++++++++------------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 101bd00e65..9a9cc652b6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,15 @@ The license applies to all entries newer than 2009-04-28. */ +2012-04-09 21:33 UTC+0200 Viktor Szakats (harbour syenar.net) + * src/rtl/fscopy.c + + using hb_file*() API instead of hb_fs*() API. + Completing TODO originating from: + https://groups.google.com/d/msg/harbour-devel/0QY0SJ8HBFU/rWbUvJXygWYJ + ; review me. I had to add an ugly-looking hack for win, because + error 38 was returned when reaching the end of file successfully. + with hb_fs*() API this didn't happen. + 2012-04-09 11:13 UTC+0200 Viktor Szakats (harbour syenar.net) * contrib/hbformat/hbfmtcls.prg ! use HB_FCOPY() instead of FRENAME() to create backup. diff --git a/harbour/src/rtl/fscopy.c b/harbour/src/rtl/fscopy.c index e365c65836..e6d4afc2a8 100644 --- a/harbour/src/rtl/fscopy.c +++ b/harbour/src/rtl/fscopy.c @@ -64,36 +64,43 @@ HB_BOOL hb_fsCopy( const char * pszSource, const char * pszDest ) { HB_ERRCODE errCode; HB_BOOL bRetVal; - HB_FHANDLE fhndSource; - HB_FHANDLE fhndDest; + PHB_FILE fileSource; + PHB_FILE fileDest; - /* TODO: Change to use hb_fileExtOpen() */ - if( ( fhndSource = hb_fsExtOpen( pszSource, NULL, FO_READ | FXO_SHARELOCK, NULL, NULL ) ) != FS_ERROR ) + if( ( fileSource = hb_fileExtOpen( pszSource, NULL, FO_READ | FXO_SHARELOCK, NULL, NULL ) ) != NULL ) { - /* TODO: Change to use hb_fileExtOpen() */ - if( ( fhndDest = hb_fsExtOpen( pszDest, NULL, FXO_TRUNCATE | FO_READWRITE | FO_EXCLUSIVE | FXO_SHARELOCK, NULL, NULL ) ) != FS_ERROR ) + if( ( fileDest = hb_fileExtOpen( pszDest, NULL, FXO_TRUNCATE | FO_READWRITE | FO_EXCLUSIVE | FXO_SHARELOCK, NULL, NULL ) ) != NULL ) { #if defined( HB_OS_UNIX ) struct stat struFileInfo; - int iSuccess = fstat( fhndSource, &struFileInfo ); + int iSuccess = fstat( hb_fileHandle( fileSource ), &struFileInfo ); #endif + HB_SIZE nBytesTotal; HB_SIZE nBytesRead; void * pbyBuffer = hb_xgrab( HB_FSCOPY_BUFFERSIZE ); + nBytesTotal = 0; + for( ;; ) { - if( ( nBytesRead = hb_fsReadLarge( fhndSource, pbyBuffer, HB_FSCOPY_BUFFERSIZE ) ) > 0 ) + if( ( nBytesRead = hb_fileReadAt( fileSource, pbyBuffer, HB_FSCOPY_BUFFERSIZE, nBytesTotal ) ) > 0 ) { - if( nBytesRead != hb_fsWriteLarge( fhndDest, pbyBuffer, nBytesRead ) ) + if( nBytesRead != hb_fileWriteAt( fileDest, pbyBuffer, nBytesRead, nBytesTotal ) ) { errCode = hb_fsError(); bRetVal = HB_FALSE; break; } + + nBytesTotal += nBytesRead; } else { errCode = hb_fsError(); + #if defined( HB_OS_WIN ) + if( errCode == 38 ) /* ERROR_HANDLE_EOF */ + errCode = 0; + #endif bRetVal = ( errCode == 0 ); break; } @@ -103,10 +110,10 @@ HB_BOOL hb_fsCopy( const char * pszSource, const char * pszDest ) #if defined( HB_OS_UNIX ) if( iSuccess == 0 ) - fchmod( fhndDest, struFileInfo.st_mode ); + fchmod( hb_fileHandle( fileDest ), struFileInfo.st_mode ); #endif - hb_fsClose( fhndDest ); + hb_fileClose( fileDest ); } else { @@ -114,7 +121,7 @@ HB_BOOL hb_fsCopy( const char * pszSource, const char * pszDest ) bRetVal = HB_FALSE; } - hb_fsClose( fhndSource ); + hb_fileClose( fileSource ); } else {