void writeToFile const uint8_t ptr size_t size const std string decode

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
void writeToFile(const uint8_t * ptr, size_t size, const std::string& decoder, const std::string& prefix)
{
#ifndef WIN32
// пытаемся записать данные для последующего дебага
std::ofstream outfile;
struct timespec ts;
timespec_get(&ts, TIME_UTC);
struct tm tm = *localtime(&ts.tv_sec);
char buf[9] = {0};
if( !strftime( buf, sizeof( buf ) - 1, "%Y-%W", &tm ))
snprintf(buf, 9, "0000-00");
std::string dir_path = "/ARCHIVE/" + std::string(buf) + std::string("/");
DIR* dp = opendir( dir_path.c_str() );
if( dp == NULL )
{
DEBUG_DATABASE_DECODER( "Folder %s not exist (full path: %s)\n", buf, dir_path.c_str());
if( mkdir(dir_path.c_str(), 0755) == -1 )
DEBUG_DATABASE_DECODER( "Can't create folder %s, errno = %i\n", dir_path.c_str(), errno);
}
outfile.open(dir_path + decoder + "_" + prefix + "_" + std::to_string(tm.tm_year + 1900) + "_" + std::to_string(tm.tm_mon + 1) +
"_" + std::to_string(tm.tm_mday) + "_" + std::to_string(tm.tm_hour) +
":" + std::to_string(tm.tm_min) + ":" + std::to_string(tm.tm_sec) +
":" + std::to_string(ts.tv_nsec),
std::ofstream::out | std::ofstream::binary);
outfile.write((const char *) ptr, size);
outfile.close();
#endif
}