use fstream in copyfile function

This commit is contained in:
Jacek Jendrzej
2016-01-29 14:49:24 +01:00
parent c796891165
commit b320878b93
2 changed files with 13 additions and 7 deletions

View File

@@ -107,7 +107,7 @@ class CServiceManager
~CServiceManager();
static CServiceManager * getInstance();
static void CopyFile(char * from, char * to);
static void CopyFile(const char * from, const char * to);
bool InitSatPosition(t_satellite_position position, const char * name = NULL, bool force = false, delivery_system_t delsys = DVB_S, uint16_t nid = 0);
bool LoadServices(bool only_current);

View File

@@ -33,6 +33,7 @@
#include <math.h>
#include <sys/time.h>
#include <unistd.h>
#include <fstream>
//#define SAVE_DEBUG
@@ -968,13 +969,18 @@ do_current:
return true;
}
void CServiceManager::CopyFile(char * from, char * to)
void CServiceManager::CopyFile(const char * from, const char * to)
{
char cmd[256] = "cp -f ";
strcat(cmd, from);
strcat(cmd, " ");
strcat(cmd, to);
system(cmd);
std::ifstream in(from, std::ios::in | std::ios::binary);
if(in.good()){
std::ofstream out(to, std::ios::out | std::ios::binary);
if(out.good()){
out << in.rdbuf();
out.close();
}
in.close();
remove(from);
}
sync();
}