From ec58530ae4aa6489db206f28fb700c6ab74cb270 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 3 Mar 2013 23:40:33 +0100 Subject: [PATCH] libconfigfile: fix strange problem in last commit for unexplained reasons, tmpfile was sometimes empty :-( to work around that, use std::string instead of const char * Signed-off-by: Jacek Jendrzej --- lib/libconfigfile/configfile.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/libconfigfile/configfile.cpp b/lib/libconfigfile/configfile.cpp index dd2cea7e3..d7713ab2e 100644 --- a/lib/libconfigfile/configfile.cpp +++ b/lib/libconfigfile/configfile.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include @@ -91,9 +93,9 @@ bool CConfigFile::loadConfig(const std::string & filename) bool CConfigFile::saveConfig(const char * const filename) { - const char *tmpname = (std::string(filename) + ".tmp").c_str(); - unlink(tmpname); - std::fstream configFile(tmpname, std::ios::out); + std::string tmpname = std::string(filename) + ".tmp"; + unlink(tmpname.c_str()); + std::fstream configFile(tmpname.c_str(), std::ios::out); if (configFile != NULL) { @@ -106,16 +108,17 @@ bool CConfigFile::saveConfig(const char * const filename) configFile.sync(); configFile.close(); - chmod(tmpname, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + chmod(tmpname.c_str(), S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* TODO: check available space? */ - rename(tmpname, filename); + rename(tmpname.c_str(), filename); modifiedFlag = false; return true; } else { - std::cerr << "[ConfigFile] Unable to open file " << filename << " for writing." << std::endl; + std::cerr << "[ConfigFile] Unable to open file " << tmpname << " for writing: " + << strerror(errno) << std::endl; return false; } }