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:
@@ -44,6 +44,7 @@
|
||||
#define FUN_DOWNLOAD 28
|
||||
#define FUN_ADDUSER 29
|
||||
#define FUN_SUBJECT 30
|
||||
#define FUN_CP 31
|
||||
|
||||
|
||||
|
||||
|
@@ -72,6 +72,7 @@ void Functions::ReadFunctions()
|
||||
AddFun(FUN_DOWNLOAD, "download");
|
||||
AddFun(FUN_ADDUSER, "adduser");
|
||||
AddFun(FUN_SUBJECT, "subject");
|
||||
AddFun(FUN_CP, "cp");
|
||||
|
||||
|
||||
// functions which need more privileges
|
||||
|
@@ -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
|
||||
|
@@ -15,7 +15,7 @@
|
||||
#include <sstream>
|
||||
#include <ctime>
|
||||
#include "item.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
void ToString(std::string & s, int value);
|
||||
@@ -64,6 +64,10 @@ bool CreateDir(const std::string & dir, int priv);
|
||||
bool CreateDirs(const char * base_dir, const char * dirs, int priv);
|
||||
bool CreateDirs(const std::string & base_dir, const std::string & dirs, int priv);
|
||||
|
||||
bool CopyFile(FILE * in, FILE * out);
|
||||
bool CopyFile(const char * src, const char * dst);
|
||||
bool CopyFile(const std::string & src, const std::string & dst);
|
||||
|
||||
const char * GetFileExt(const char * name);
|
||||
Item::Auth SelectFileType(const char * file_name);
|
||||
|
||||
|
Reference in New Issue
Block a user