diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2014-05-06 21:50:25 -0700 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-05-06 21:50:25 -0700 |
commit | df4f88fe3198acea6267c6ed3b129af7d8972bf1 (patch) | |
tree | 12aa58e43bdd457f8fccd5fef49dc6831368f0f3 /src/os/time.c | |
parent | 85459327ba76d674572ad96dc459c97e4a71e88d (diff) | |
parent | 151382d533c2bd77e26e1dfc254e186f7496e226 (diff) | |
download | rneovim-df4f88fe3198acea6267c6ed3b129af7d8972bf1.tar.gz rneovim-df4f88fe3198acea6267c6ed3b129af7d8972bf1.tar.bz2 rneovim-df4f88fe3198acea6267c6ed3b129af7d8972bf1.zip |
Merge pull request #644 from philix/log
Macro-based log utility for Neovim
Diffstat (limited to 'src/os/time.c')
-rw-r--r-- | src/os/time.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/os/time.c b/src/os/time.c index 0f7c990e23..1dc7ca68d4 100644 --- a/src/os/time.c +++ b/src/os/time.c @@ -1,5 +1,6 @@ #include <stdint.h> #include <stdbool.h> +#include <sys/time.h> #include <uv.h> @@ -59,3 +60,27 @@ static void microdelay(uint64_t microseconds) uv_mutex_unlock(&delay_mutex); } + +struct tm *os_localtime_r(const time_t *clock, struct tm *result) +{ +#ifdef UNIX + // POSIX provides localtime_r() as a thread-safe version of localtime(). + return localtime_r(clock, result); +#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(clock); // NOLINT + *result = *local_time; +return result; +#endif +} + +struct tm *os_get_localtime(struct tm *result) +{ + struct timeval tv; + if (gettimeofday(&tv, NULL) < 0) { + return NULL; + } + + return os_localtime_r(&tv.tv_sec, result); +} |