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 <crashdvb@googlemail.com>


Origin commit data
------------------
Branch: ni/coolstream
Commit: ec58530ae4
Author: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: 2013-03-03 (Sun, 03 Mar 2013)



------------------
This commit was generated by Migit
This commit is contained in:
Stefan Seyfried
2013-03-03 23:40:33 +01:00
committed by Jacek Jendrzej
parent f6846b1062
commit 32909385e9

View File

@@ -29,6 +29,8 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <cstdlib> #include <cstdlib>
#include <cerrno>
#include <cstring>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
@@ -91,9 +93,9 @@ bool CConfigFile::loadConfig(const std::string & filename)
bool CConfigFile::saveConfig(const char * const filename) bool CConfigFile::saveConfig(const char * const filename)
{ {
const char *tmpname = (std::string(filename) + ".tmp").c_str(); std::string tmpname = std::string(filename) + ".tmp";
unlink(tmpname); unlink(tmpname.c_str());
std::fstream configFile(tmpname, std::ios::out); std::fstream configFile(tmpname.c_str(), std::ios::out);
if (configFile != NULL) if (configFile != NULL)
{ {
@@ -106,16 +108,17 @@ bool CConfigFile::saveConfig(const char * const filename)
configFile.sync(); configFile.sync();
configFile.close(); 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? */ /* TODO: check available space? */
rename(tmpname, filename); rename(tmpname.c_str(), filename);
modifiedFlag = false; modifiedFlag = false;
return true; return true;
} }
else 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; return false;
} }
} }