revision to copyfile.c

This commit is contained in:
Andi Jahja
1999-06-24 12:44:35 +00:00
parent 60096cefa1
commit 227eb12bb1
2 changed files with 60 additions and 36 deletions

View File

@@ -1,3 +1,7 @@
19990624-13:00 WIB Andi Jahja <andij@aonlippo.co.id>
* source/rtl/copyfile.c
- add run time error
19990623-23:25 EDT David G. Holm <dholm@jsd-llc.com>
* source/rtl/console.c
- The non-GT API version of DISPBOX() was creating boxes that

View File

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