Commit d9e10c4f authored by Martin Marinov's avatar Martin Marinov
Browse files

Refactored the Debug::File::Impl::add_time() implementation to System::Environment::time().

parent cd991428
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "DebFile.hh" #include "DebFile.hh"
#include "DebCallStack.hh" #include "DebCallStack.hh"
#include "DebDefault.hh" #include "DebDefault.hh"
#include "Base/Utils/Environment.hh"
#include <string> #include <string>
#include <fstream> #include <fstream>
...@@ -16,7 +17,6 @@ ...@@ -16,7 +17,6 @@
#include <map> #include <map>
#include <sstream> #include <sstream>
#include <cstring> #include <cstring>
#include <time.h>
#ifndef WIN32 #ifndef WIN32
#define sprintf_s snprintf #define sprintf_s snprintf
...@@ -276,32 +276,7 @@ public: ...@@ -276,32 +276,7 @@ public:
} }
// Append current asctime to given string // Append current asctime to given string
bool add_time(std::string& str) void add_time(std::string& str) { str += System::Environment::time(); }
{
time_t rawtime;
time(&rawtime);
struct tm timeinfo;
#ifdef WIN32
int err = localtime_s(&timeinfo, &rawtime);
if (err == 0)
{
char buffer[256];
err = asctime_s(buffer, sizeof(buffer), &timeinfo);
if (err == 0)
{
str.append(buffer);
return true;
}
}
#else//WIN32
//TODO: Implement a secure version of this code for Linux, OSX
//timeinfo = *localtime(&rawtime);
//char* buffer = asctime(&timeinfo);
str.append("TODO: add_time()");
#endif//WIN32
return false;
}
#if 1 #if 1
bool hover(std::string& _str, const std::string& _hover, const bool _open) bool hover(std::string& _str, const std::string& _hover, const bool _open)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <cstdlib> #include <cstdlib>
#include <locale.h> #include <locale.h>
#include <locale> #include <locale>
#include <time.h>
namespace System { namespace System {
namespace Environment { namespace Environment {
...@@ -47,5 +48,29 @@ LocaleSession::~LocaleSession() ...@@ -47,5 +48,29 @@ LocaleSession::~LocaleSession()
std::locale::global(lcl_bckp_); std::locale::global(lcl_bckp_);
} }
std::string time()
{
time_t rawtime;
::time(&rawtime);
struct tm timeinfo;
#ifdef WIN32
int err = ::localtime_s(&timeinfo, &rawtime);
if (err == 0)
{
char buffer[256];
err = asctime_s(buffer, sizeof(buffer), &timeinfo);
if (err == 0)
return std::string(buffer);
}
#else//WIN32
//TODO: Implement a secure version of this code for Linux, OSX
//timeinfo = *localtime(&rawtime);
//char* buffer = asctime(&timeinfo);
str.append("TODO: add_time()");
#endif//WIN32
return std::string();
}
}//namespace Environment }//namespace Environment
}//namespace System }//namespace System
...@@ -48,6 +48,10 @@ private: ...@@ -48,6 +48,10 @@ private:
std::locale lcl_bckp_; std::locale lcl_bckp_;
}; };
//! Return the system time in a string
std::string time();
}//namespace Environment }//namespace Environment
}//namespace System }//namespace System
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment