aboutsummaryrefslogtreecommitdiff
path: root/src/log.c
diff options
context:
space:
mode:
authorFelipe Oliveira Carvalho <felipekde@gmail.com>2014-05-01 20:24:29 -0300
committerFelipe Oliveira Carvalho <felipekde@gmail.com>2014-05-06 09:22:39 -0300
commit151382d533c2bd77e26e1dfc254e186f7496e226 (patch)
treec3841dddf47c5d75cdc1a11fe5e726c2f1c6bbf2 /src/log.c
parentee62510d4e623e5fb4a0cc7d5b450ce18c24e25f (diff)
downloadrneovim-151382d533c2bd77e26e1dfc254e186f7496e226.tar.gz
rneovim-151382d533c2bd77e26e1dfc254e186f7496e226.tar.bz2
rneovim-151382d533c2bd77e26e1dfc254e186f7496e226.zip
Introduce os_localtime_r() and os_get_local_time()
Replace localtime() with os_localtime_r() in `eval.c` and `undo.c`.
Diffstat (limited to 'src/log.c')
-rw-r--r--src/log.c17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/log.c b/src/log.c
index d67851c2d4..5d536c62e5 100644
--- a/src/log.c
+++ b/src/log.c
@@ -11,6 +11,7 @@
#include "misc1.h"
#include "types.h"
#include "os/os.h"
+#include "os/time.h"
#define USR_LOG_FILE "$HOME/.nvimlog"
@@ -117,23 +118,13 @@ static bool v_do_log_to_file(FILE *log_file, int log_level,
assert(log_level >= DEBUG_LOG_LEVEL && log_level <= ERROR_LOG_LEVEL);
// format current timestamp in local time
- struct timeval tv;
- if (gettimeofday(&tv, NULL) < 0) {
+ struct tm local_time;
+ if (os_get_localtime(&local_time) == NULL) {
return false;
}
-#ifdef UNIX
- // localtime() is not thread-safe. POSIX provides localtime_r() as a
- // thread-safe version.
- struct tm local_time_allocated;
- struct tm *local_time = localtime_r(&tv.tv_sec, &local_time_allocated);
-#else
- // Windows version of localtime() is thread-safe.
- // See http://msdn.microsoft.com/en-us/library/bf12f0hc%28VS.80%29.aspx
- struct tm *local_time = localtime(&tv.tv_sec); // NOLINT
-#endif
char date_time[20];
if (strftime(date_time, sizeof(date_time), "%Y/%m/%d %H:%M:%S",
- local_time) == 0) {
+ &local_time) == 0) {
return false;
}