From f618ce2a8d0ba7fdb3dedce5cac04479a9568b91 Mon Sep 17 00:00:00 2001 From: psychon Date: Wed, 18 Mar 2009 15:40:05 +0000 Subject: [PATCH] Add CFile::Sync() This adds a simple wrapper for fsync() to CFileUtils. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1431 726aef4b-f618-498e-8847-2d620e286838 --- FileUtils.cpp | 8 ++++++++ FileUtils.h | 1 + 2 files changed, 9 insertions(+) diff --git a/FileUtils.cpp b/FileUtils.cpp index 0a7ff158..d497a20b 100644 --- a/FileUtils.cpp +++ b/FileUtils.cpp @@ -254,6 +254,14 @@ bool CFile::Truncate() { return false; } +bool CFile::Sync() { + if (m_iFD != -1 && fsync(m_iFD) == 0) { + return true; + } + + return false; +} + bool CFile::Open(const CString& sFileName, int iFlags, mode_t iMode) { SetFileName(sFileName); return Open(iFlags, iMode); diff --git a/FileUtils.h b/FileUtils.h index ab7e674a..91b340c7 100644 --- a/FileUtils.h +++ b/FileUtils.h @@ -98,6 +98,7 @@ public: static bool Chmod(const CString& sFile, mode_t mode); bool Seek(unsigned long uPos); bool Truncate(); + bool Sync(); bool Open(const CString& sFileName, int iFlags = O_RDONLY, mode_t iMode = 0644); bool Open(int iFlags = O_RDONLY, mode_t iMode = 0644); int Read(char *pszBuffer, int iBytes);