mirror of
https://github.com/znc/znc.git
synced 2026-05-06 21:42:28 +02: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);
|
||||
}
|
||||
|
||||
@@ -89,9 +89,11 @@ public:
|
||||
//
|
||||
int Delete();
|
||||
int Move(const CString& sNewFileName, bool bOverwrite = false);
|
||||
int Copy(const CString& sNewFileName, bool bOverwrite = false);
|
||||
|
||||
static bool Delete(const CString& sFileName);
|
||||
static bool Move(const CString& sOldFileName, const CString& sNewFileName, bool bOverwrite = false);
|
||||
static bool Copy(const CString& sOldFileName, const CString& sNewFileName, bool bOverwrite = false);
|
||||
bool Chmod(mode_t mode);
|
||||
static bool Chmod(const CString& sFile, mode_t mode);
|
||||
bool Seek(unsigned long uPos);
|
||||
|
||||
Reference in New Issue
Block a user