mirror of
https://github.com/znc/znc.git
synced 2026-03-28 17:42:41 +01:00
Added Copy()
git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@447 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user