fopen_s adapter in details::os

This commit is contained in:
gabi 2014-10-18 23:28:16 +03:00
parent f4d9c31a2f
commit 0c6a0d52d7

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include<string> #include<string>
#include<cstdio> #include<cstdio>
#include<ctime> #include<ctime>
@ -13,10 +14,11 @@ namespace os
inline std::tm localtime(const std::time_t &time_tt) inline std::tm localtime(const std::time_t &time_tt)
{ {
std::tm tm;
#ifdef _WIN32 #ifdef _WIN32
std::tm tm;
localtime_s(&tm, &time_tt); localtime_s(&tm, &time_tt);
#else #else
std::tm tm;
localtime_r(&time_tt, &tm); localtime_r(&time_tt, &tm);
#endif #endif
return tm; return tm;
@ -64,11 +66,22 @@ inline unsigned short eol_size()
#else #else
constexpr inline unsigned short eol_size() constexpr inline unsigned short eol_size()
{ {
return 1; return 1;
} }
#endif #endif
//fopen_s on non windows for writing
inline bool fopen_s(FILE** fp, const std::string& filename, const char* mode)
{
#ifdef _WIN32
return fopen_s(fp, filename, mode);
#else
*fp = fopen((filename.c_str()), mode);
return fp == nullptr;
#endif
}
} //os } //os
} //details } //details
} //c11log } //c11log