added: function cp (only for files)
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@605 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -653,7 +653,64 @@ bool CreateDirs(const std::string & base_dir, const std::string & dirs, int priv
|
||||
|
||||
|
||||
|
||||
bool CopyFile(FILE * in, FILE * out)
|
||||
{
|
||||
char buf[1024];
|
||||
size_t buflen = sizeof(buf)/sizeof(char);
|
||||
size_t len;
|
||||
|
||||
do
|
||||
{
|
||||
len = fread(buf, 1, buflen, in);
|
||||
|
||||
if( len > 0 )
|
||||
fwrite(buf, 1, len, out);
|
||||
|
||||
if( ferror(in) || ferror(out) )
|
||||
return false;
|
||||
}
|
||||
while( !feof(in) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CopyFile(const char * src, const char * dst)
|
||||
{
|
||||
FILE * in, * out;
|
||||
|
||||
in = fopen(src, "rb");
|
||||
|
||||
if( !in )
|
||||
return false;
|
||||
|
||||
out = fopen(dst, "wb");
|
||||
|
||||
if( !out )
|
||||
{
|
||||
fclose(in);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool res = CopyFile(in, out);
|
||||
|
||||
fclose(in);
|
||||
fclose(out);
|
||||
|
||||
if( res && ferror(out) )
|
||||
res = false;
|
||||
|
||||
if( !res )
|
||||
remove(dst);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool CopyFile(const std::string & src, const std::string & dst)
|
||||
{
|
||||
return CopyFile(src.c_str(), dst.c_str());
|
||||
}
|
||||
|
||||
|
||||
// if there is not an extension it returns a pointer to the last '\0' character
|
||||
|
Reference in New Issue
Block a user