diff options
author | rubidium42 <rubidium@openttd.org> | 2021-05-13 10:00:41 +0200 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-14 23:22:29 +0200 |
commit | aa5a8fe28a224fd581b6053e4a5ce38f3e1a9694 (patch) | |
tree | 3641fec62fd2f0969ce0ac06b4f7670d7e43c9f4 /src/console_cmds.cpp | |
parent | 297d6e20bf0467d2a42e49bee291829ce3bb7c58 (diff) | |
download | openttd-aa5a8fe28a224fd581b6053e4a5ce38f3e1a9694.tar.xz |
Codechange: use thread safe time functions
Functions like localtime, gmtime and asctime are not thread safe as they (might) reuse the same buffer. So use the safer _s/_r variant for localtime and gmtime, and use strftime in favour of asctime.
Diffstat (limited to 'src/console_cmds.cpp')
-rw-r--r-- | src/console_cmds.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index a417831cb..39a52f0b5 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -41,7 +41,7 @@ #include "rail.h" #include "game/game.hpp" #include "table/strings.h" -#include <time.h> +#include "walltime_func.h" #include "safeguards.h" @@ -1369,10 +1369,9 @@ DEF_CONSOLE_CMD(ConGetSysDate) return true; } - time_t t; - time(&t); - auto timeinfo = localtime(&t); - IConsolePrintF(CC_DEFAULT, "System Date: %04d-%02d-%02d %02d:%02d:%02d", timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); + char buffer[lengthof("2000-01-02 03:04:05")]; + LocalTime::Format(buffer, lastof(buffer), "%Y-%m-%d %H:%M:%S"); + IConsolePrintF(CC_DEFAULT, "System Date: %s", buffer); return true; } |