diff options
author | ipknHama <ipknhama@gmail.com> | 2015-02-20 11:07:23 +0900 |
---|---|---|
committer | ipknHama <ipknhama@gmail.com> | 2015-02-20 11:07:23 +0900 |
commit | 92cf40e053d98e34a76944925555f74a44aa61a7 (patch) | |
tree | 8655f7b8f622ce6b4fa9c1e4faf426edd551fb6b /include/logging.h | |
parent | f1d1fd6480facb5d20fea401bb2695b3573b6f02 (diff) | |
download | crow-92cf40e053d98e34a76944925555f74a44aa61a7.tar.gz crow-92cf40e053d98e34a76944925555f74a44aa61a7.zip |
change `gmtime` to the safer version
Diffstat (limited to 'include/logging.h')
-rw-r--r-- | include/logging.h | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/include/logging.h b/include/logging.h index 0d77071..b915e6e 100644 --- a/include/logging.h +++ b/include/logging.h @@ -39,9 +39,18 @@ namespace crow static std::string timestamp() { char date[32]; - time_t t = time(0); - strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", gmtime(&t)); - return std::string(date); + time_t t = time(0); + + tm my_tm; + +#ifdef _MSC_VER + gmtime_s(&my_tm, &t); +#else + gmtime_r(&t, &my_tm); +#endif + + size_t sz = strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", &my_tm); + return std::string(date, date+sz); } public: |