From: Maxim Mamontov Date: Fri, 10 Dec 2010 15:34:24 +0000 (+0200) Subject: В класс CONFIGFILE добавлена поддержка записи с переименованием X-Git-Tag: 2.407-rc3~280 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/e7c6f85eecb6863620be677106173e1824c9a578 В класс CONFIGFILE добавлена поддержка записи с переименованием --- 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