...
 
Commits (1)
  • Rob Swindell's avatar
    Replace fcopy with CopyFile (Win32 API function) on Windows. · 047ca2f8
    Rob Swindell authored
    Thanks to Wilfred van Velzen (2:280/464) for the tip. CopyFile() reduced
    the 1GB file copy test (from and to CIFS/SMB) duration from 37 seconds
    to 5 seconds with very low CPU utilization!
    Created a wrapper for non-Windows OSes in xpdev/dirwrap. This is where
    non-Windows-OS-specific optimized versions may appear in the future,
    but for now it's just the previous fcopy() implementation (using a 256KB
    stack buffer). sbbs doesn't actually copy files very often, so this
    isn't as big of a deal as one might assume. The JavaScript global
    method: file_copy() also benefits from these improvements, so any
    scripts that use it (e.g. tickit.js) will also benefit. binkit.js has
    its own file-copy logic (using a 2MB buffer), so no change there.
    047ca2f8
......@@ -3047,7 +3047,7 @@ js_fcopy(JSContext *cx, uintN argc, jsval *arglist)
}
rc=JS_SUSPENDREQUEST(cx);
ret=fcopy(src,dest);
ret = CopyFile(src, dest, /* failIfExists: */FALSE);
free(src);
free(dest);
JS_RESUMEREQUEST(cx, rc);
......
......@@ -148,38 +148,6 @@ BOOL fmutex(const char* fname, const char* text, long max_age)
return TRUE;
}
BOOL fcopy(const char* src, const char* dest)
{
uint8_t buf[256 * 1024];
ulong count=0;
FILE* in;
FILE* out;
BOOL success=TRUE;
if((in=fopen(src,"rb"))==NULL)
return FALSE;
if((out=fopen(dest,"wb"))==NULL) {
fclose(in);
return FALSE;
}
while(!feof(in)) {
size_t rd = fread(buf, sizeof(uint8_t), sizeof(buf), in);
if(rd < 1)
break;
if(fwrite(buf, sizeof(uint8_t), rd, out) != rd) {
success = FALSE;
break;
}
MAYBE_YIELD();
}
fclose(in);
fclose(out);
return(success);
}
BOOL fcompare(const char* fn1, const char* fn2)
{
FILE* fp1;
......@@ -240,7 +208,7 @@ BOOL backup(const char *fname, int backup_level, BOOL ren)
/* preserve the original time stamp */
ut.modtime = fdate(fname);
if(!fcopy(fname,newname))
if(!CopyFile(fname, newname, /* failIfExists: */FALSE))
return FALSE;
ut.actime = time(NULL);
......
......@@ -47,7 +47,6 @@ int nopen(const char* str, int access);
FILE * fnopen(int* file, const char* str, int access);
BOOL ftouch(const char* fname);
BOOL fmutex(const char* fname, const char* text, long max_age);
BOOL fcopy(const char* src, const char* dest);
BOOL fcompare(const char* fn1, const char* fn2);
BOOL backup(const char* org, int backup_level, BOOL ren);
......
......@@ -1236,7 +1236,7 @@ bool sbbs_t::editfile(char *fname, bool msg)
if(stricmp(msgtmp,path)) {
removecase(msgtmp);
if(fexistcase(path))
fcopy(path, msgtmp);
CopyFile(path, msgtmp, /* failIfExists: */FALSE);
}
editor_inf(useron_xedit,/* to: */fname,/* from: */nulstr,/* subj: */nulstr,/* mode: */0,INVALID_SUB,/* tagfile: */NULL);
......
......@@ -1218,3 +1218,39 @@ int DLLCALL mkpath(const char* path)
return(result);
}
#if !defined _WIN32
BOOL CopyFile(const char* src, const char* dest, BOOL failIfExists)
{
uint8_t buf[256 * 1024];
ulong count=0;
FILE* in;
FILE* out;
BOOL success=TRUE;
if(failIfExists && fexist(dest))
return FALSE;
if((in=fopen(src,"rb"))==NULL)
return FALSE;
if((out=fopen(dest,"wb"))==NULL) {
fclose(in);
return FALSE;
}
while(!feof(in)) {
size_t rd = fread(buf, sizeof(uint8_t), sizeof(buf), in);
if(rd < 1)
break;
if(fwrite(buf, sizeof(uint8_t), rd, out) != rd) {
success = FALSE;
break;
}
MAYBE_YIELD();
}
fclose(in);
fclose(out);
return success;
}
#endif
......@@ -250,6 +250,10 @@ DLLEXPORT int DLLCALL removecase(const char *path);
#define removecase(x) remove(x)
#endif
#if !defined _WIN32
DLLEXPORT BOOL CopyFile(const char* src, const char* dest, BOOL failIfExists);
#endif
#if defined(__cplusplus)
}
#endif
......