From 227eb12bb17a99d36912c46df2e3c6175f3459ef Mon Sep 17 00:00:00 2001 From: Andi Jahja Date: Thu, 24 Jun 1999 12:44:35 +0000 Subject: [PATCH] revision to copyfile.c --- harbour/ChangeLog | 4 ++ harbour/source/rtl/copyfile.c | 92 +++++++++++++++++++++-------------- 2 files changed, 60 insertions(+), 36 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index dd3b634621..aa4c08e364 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,7 @@ +19990624-13:00 WIB Andi Jahja + * source/rtl/copyfile.c + - add run time error + 19990623-23:25 EDT David G. Holm * source/rtl/console.c - The non-GT API version of DISPBOX() was creating boxes that diff --git a/harbour/source/rtl/copyfile.c b/harbour/source/rtl/copyfile.c index ffda94f3da..c1e5a062bb 100644 --- a/harbour/source/rtl/copyfile.c +++ b/harbour/source/rtl/copyfile.c @@ -12,45 +12,65 @@ static long hb_fsCopy(BYTEP ,BYTEP ) ; -HARBOUR HB___COPYFILE() { - if ( ISCHAR(1) && ISCHAR(2) ) { - hb_retnl(hb_fsCopy((BYTEP)hb_parc(1),(BYTEP)hb_parc(2))); - } - return; +HARBOUR HB___COPYFILE( void ) + +{ + PHB_ITEM pError; + if ( ISCHAR(1) && ISCHAR(2) ) + hb_retnl(hb_fsCopy((BYTEP)hb_parc(1),(BYTEP)hb_parc(2))); + else + { + pError = hb_errNew(); + hb_errPutDescription(pError, "Error BASE/2010 Argument error: __COPYFILE" ); + hb_errLaunch(pError); + hb_errRelease(pError); + } + return; } -static long hb_fsCopy(BYTEP source,BYTEP dest) { - FHANDLE dHANDLE,sHANDLE; - char *buffer; - USHORT usCount; - ULONG ulCount = 0L; +static long hb_fsCopy(BYTEP source,BYTEP dest) + +{ + FHANDLE dHANDLE,sHANDLE; + char *buffer; + USHORT usCount; + ULONG ulCount = 0L; + PHB_ITEM pError; sHANDLE = hb_fsOpen(source, FO_READ); - if ( ! hb_fsError() ) { - dHANDLE = hb_fsCreate(dest,FC_NORMAL); - if ( hb_fsError() ) { - hb_fsClose(sHANDLE); - return( -2L) ; - } - buffer = hb_xgrab(BUFFER_SIZE); - if (buffer == NULL) { - hb_fsClose(sHANDLE); - hb_fsClose(dHANDLE); - return(-3L); - } - usCount = hb_fsRead(sHANDLE,buffer,BUFFER_SIZE); - while(1) { - ulCount += (ULONG)usCount; - hb_fsWrite(dHANDLE,buffer, usCount); - usCount = hb_fsRead(sHANDLE,buffer, BUFFER_SIZE); - if (usCount != BUFFER_SIZE ) { - break; - } - } - ulCount += (ULONG)usCount; - hb_fsWrite(dHANDLE,buffer,usCount); - hb_xfree(buffer); - hb_fsClose(sHANDLE); - hb_fsClose(dHANDLE); + if ( hb_fsError() ) + { + pError = hb_errNew(); + hb_errPutDescription(pError, "Error BASE/2012 Open error: __COPYFILE" ); + hb_errLaunch(pError); + hb_errRelease(pError); + return( -1L) ; } + dHANDLE = hb_fsCreate(dest,FC_NORMAL); + if ( hb_fsError() ) + { + hb_fsClose(sHANDLE); + pError = hb_errNew(); + hb_errPutDescription(pError, "Error BASE/2012 Create error: __COPYFILE" ); + hb_errLaunch(pError); + hb_errRelease(pError); + return( -2L) ; + } + buffer = hb_xgrab( BUFFER_SIZE ); + usCount = hb_fsRead(sHANDLE,buffer,BUFFER_SIZE); + while( TRUE ) + { + ulCount += (ULONG)usCount; + hb_fsWrite(dHANDLE,buffer, usCount); + usCount = hb_fsRead(sHANDLE,buffer,BUFFER_SIZE); + if (usCount != BUFFER_SIZE ) + { + break; + } + } + ulCount += (ULONG)usCount; + hb_fsWrite(dHANDLE,buffer,usCount); + hb_xfree(buffer); + hb_fsClose(sHANDLE); + hb_fsClose(dHANDLE); return( ulCount ); }