diff options
author | Riccardo Spagni <ric@spagni.net> | 2018-12-04 17:29:46 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2018-12-04 17:29:46 +0200 |
commit | d4a0fb2b895f073c0852bdd42cd05ef4eeb21e3c (patch) | |
tree | 71f245b66e10da5d95b48925bdadbcde5d7e3493 | |
parent | Merge pull request #4878 (diff) | |
parent | blockchain_stats: don't use gmtime_r on Windows (diff) | |
download | monero-d4a0fb2b895f073c0852bdd42cd05ef4eeb21e3c.tar.xz |
Merge pull request #4880
96e6b439 blockchain_stats: don't use gmtime_r on Windows (moneromooo-monero)
-rw-r--r-- | contrib/epee/include/misc_os_dependent.h | 9 | ||||
-rw-r--r-- | contrib/epee/src/mlog.cpp | 8 | ||||
-rw-r--r-- | src/blockchain_utilities/blockchain_stats.cpp | 2 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 6 |
4 files changed, 13 insertions, 12 deletions
diff --git a/contrib/epee/include/misc_os_dependent.h b/contrib/epee/include/misc_os_dependent.h index 0d09683d6..5fffde8d5 100644 --- a/contrib/epee/include/misc_os_dependent.h +++ b/contrib/epee/include/misc_os_dependent.h @@ -124,5 +124,14 @@ namespace misc_utils return boost::lexical_cast<std::string>(pthread_self()); #endif } + + inline bool get_gmt_time(time_t t, struct tm &tm) + { +#ifdef _WIN32 + return gmtime_s(&tm, &t); +#else + return gmtime_r(&t, &tm); +#endif + } } } diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp index 638155b6b..00d848388 100644 --- a/contrib/epee/src/mlog.cpp +++ b/contrib/epee/src/mlog.cpp @@ -40,6 +40,7 @@ #include <boost/filesystem.hpp> #include <boost/algorithm/string.hpp> #include "string_tools.h" +#include "misc_os_dependent.h" #include "misc_log_ex.h" #undef MONERO_DEFAULT_LOG_CATEGORY @@ -58,12 +59,7 @@ static std::string generate_log_filename(const char *base) char tmp[200]; struct tm tm; time_t now = time(NULL); - if -#ifdef WIN32 - (!gmtime_s(&tm, &now)) -#else - (!gmtime_r(&now, &tm)) -#endif + if (!epee::misc_utils::get_gmt_time(now, tm)) snprintf(tmp, sizeof(tmp), "part-%u", ++fallback_counter); else strftime(tmp, sizeof(tmp), "%Y-%m-%d-%H-%M-%S", &tm); diff --git a/src/blockchain_utilities/blockchain_stats.cpp b/src/blockchain_utilities/blockchain_stats.cpp index 716b33cae..aae8f333b 100644 --- a/src/blockchain_utilities/blockchain_stats.cpp +++ b/src/blockchain_utilities/blockchain_stats.cpp @@ -234,7 +234,7 @@ plot 'stats.csv' index "DATA" using (timecolumn(1,"%Y-%m-%d")):4 with lines, '' } time_t tt = blk.timestamp; char timebuf[64]; - gmtime_r(&tt, &currtm); + epee::misc_utils::get_gmt_time(tt, currtm); if (!prevtm.tm_year) prevtm = currtm; // catch change of day diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 77eacaf16..6e657b057 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -6731,11 +6731,7 @@ static std::string get_human_readable_timestamp(uint64_t ts) return "<unknown>"; time_t tt = ts; struct tm tm; -#ifdef WIN32 - gmtime_s(&tm, &tt); -#else - gmtime_r(&tt, &tm); -#endif + epee::misc_utils::get_gmt_time(tt, tm); uint64_t now = time(NULL); uint64_t diff = ts > now ? ts - now : now - ts; strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &tm); |