From e7c6f85eecb6863620be677106173e1824c9a578 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Fri, 10 Dec 2010 17:34:24 +0200 Subject: [PATCH] =?utf8?q?=D0=92=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20CONFIG?= =?utf8?q?FILE=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20?= =?utf8?q?=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=20=D0=B7?= =?utf8?q?=D0=B0=D0=BF=D0=B8=D1=81=D0=B8=20=D1=81=20=D0=BF=D0=B5=D1=80?= =?utf8?q?=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?utf8?q?=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- stglibs/conffiles.lib/conffiles.cpp | 62 +++++++++++++++++++---------- stglibs/conffiles.lib/conffiles.h | 2 + 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/stglibs/conffiles.lib/conffiles.cpp b/stglibs/conffiles.lib/conffiles.cpp index b247d041..cf7dffee 100644 --- a/stglibs/conffiles.lib/conffiles.cpp +++ b/stglibs/conffiles.lib/conffiles.cpp @@ -28,7 +28,12 @@ */ //--------------------------------------------------------------------------- -#include + +// getpid +#include +#include + +#include // E* #include #include @@ -98,27 +103,6 @@ int e = error; error = 0; return e; } -//--------------------------------------------------------------------------- -int CONFIGFILE::Flush() const -{ -ofstream f(fileName.c_str()); -if (!f.is_open()) - { - error = EIO; - return EIO; - } - -map::const_iterator it = param_val.begin(); -while (it != param_val.end()) - { - f << it->first << "=" << it->second << "\n"; - ++it; - } - -f.close(); - -return 0; -} /*//--------------------------------------------------------------------------- int CONFIGFILE::ReadString(const string & param, char * str, int * maxLen, const char * defaultVal) const { @@ -391,3 +375,37 @@ snprintf(s, 30, "%f", val); param_val[param] = s; } //--------------------------------------------------------------------------- +int CONFIGFILE::Flush(const std::string & path) const +{ +ofstream f(path.c_str()); +if (!f.is_open()) + { + error = EIO; + return EIO; + } + +map::const_iterator it = param_val.begin(); +while (it != param_val.end()) + { + f << it->first << "=" << it->second << "\n"; + ++it; + } + +f.close(); +return 0; +} +//--------------------------------------------------------------------------- +int CONFIGFILE::Flush() const +{ +std::string pid; +x2str(getpid(), pid); + +if (Flush(fileName + "." + pid)) + return -1; + +if (rename((fileName + "." + pid).c_str(), fileName.c_str())) + return -1; + +return 0; +} +//--------------------------------------------------------------------------- diff --git a/stglibs/conffiles.lib/conffiles.h b/stglibs/conffiles.lib/conffiles.h index 07f716cd..77a696d0 100644 --- a/stglibs/conffiles.lib/conffiles.h +++ b/stglibs/conffiles.lib/conffiles.h @@ -76,6 +76,8 @@ private: map param_val; string fileName; mutable int error; + + int Flush(const std::string & path) const; }; //--------------------------------------------------------------------------- #endif -- 2.44.2