Added Copy()

git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@447 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
prozacx
2005-07-18 04:11:09 +00:00
parent 29e14b42f5
commit 6be9f989cb
2 changed files with 35 additions and 0 deletions

View File

@@ -136,6 +136,10 @@ int CFile::Move(const CString& sNewFileName, bool bOverwrite) {
return CFile::Move(m_sLongName, sNewFileName, bOverwrite);
}
int CFile::Copy(const CString& sNewFileName, bool bOverwrite) {
return CFile::Copy(m_sLongName, sNewFileName, bOverwrite);
}
bool CFile::Delete(const CString& sFileName) {
if(!CFile::Exists(sFileName)) {
return false;
@@ -153,6 +157,35 @@ bool CFile::Move(const CString& sOldFileName, const CString& sNewFileName, bool
return (rename(sOldFileName.c_str(), sNewFileName.c_str()) == 0) ? true : false;
}
bool CFile::Copy(const CString& sOldFileName, const CString& sNewFileName, bool bOverwrite) {
if((!bOverwrite) && (CFile::Exists(sNewFileName))) {
return false;
}
CFile OldFile(sOldFileName);
CFile NewFile(sNewFileName);
if (!OldFile.Open(O_RDONLY)) {
return false;
}
if (!NewFile.Open(O_WRONLY | O_CREAT | O_TRUNC)) {
return false;
}
char szBuf[8192];
unsigned int len = 0;
while ((len = OldFile.Read(szBuf, 100))) {
NewFile.Write(szBuf, len);
}
OldFile.Close();
NewFile.Close();
return true;
}
bool CFile::Chmod(mode_t mode) {
return CFile::Chmod(m_sLongName, mode);
}