diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2014-07-20 18:27:49 -0400 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2014-07-20 18:27:49 -0400 |
commit | 845d1bfa905cf0d28d9a1a662e42525449dd1be4 (patch) | |
tree | 2d7e5956df2c749033950f786c364b019204ed7f /src | |
parent | a9d679b1d703ff6213651e54e035fcf5ee8d88d0 (diff) | |
parent | 636ddd075c8fdfffcac22281120baed9f293b266 (diff) | |
download | rneovim-845d1bfa905cf0d28d9a1a662e42525449dd1be4.tar.gz rneovim-845d1bfa905cf0d28d9a1a662e42525449dd1be4.tar.bz2 rneovim-845d1bfa905cf0d28d9a1a662e42525449dd1be4.zip |
Merge #965 'Make os_get_localtime() portable + fix bug on win'
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/os/time.c | 20 | ||||
-rw-r--r-- | src/nvim/os/time.h | 1 |
2 files changed, 11 insertions, 10 deletions
diff --git a/src/nvim/os/time.c b/src/nvim/os/time.c index 00ffccfaa8..e3b76ac833 100644 --- a/src/nvim/os/time.c +++ b/src/nvim/os/time.c @@ -1,6 +1,6 @@ #include <stdint.h> #include <stdbool.h> -#include <sys/time.h> +#include <time.h> #include <uv.h> @@ -84,7 +84,8 @@ static void microdelay(uint64_t microseconds) /// Portable version of POSIX localtime_r() /// /// @return NULL in case of error -struct tm *os_localtime_r(const time_t *clock, struct tm *result) +struct tm *os_localtime_r(const time_t *restrict clock, + struct tm *restrict result) FUNC_ATTR_NONNULL_ALL { #ifdef UNIX // POSIX provides localtime_r() as a thread-safe version of localtime(). @@ -93,8 +94,11 @@ struct tm *os_localtime_r(const time_t *clock, struct tm *result) // 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 + if (!local_time) { + return NULL; + } *result = *local_time; -return result; + return result; #endif } @@ -103,12 +107,8 @@ return result; /// @param result Pointer to a 'struct tm' where the result should be placed /// @return A pointer to a 'struct tm' in the current time zone (the 'result' /// argument) or NULL in case of error -struct tm *os_get_localtime(struct tm *result) +struct tm *os_get_localtime(struct tm *result) FUNC_ATTR_NONNULL_ALL { - struct timeval tv; - if (gettimeofday(&tv, NULL) < 0) { - return NULL; - } - - return os_localtime_r(&tv.tv_sec, result); + time_t rawtime = time(NULL); + return os_localtime_r(&rawtime, result); } diff --git a/src/nvim/os/time.h b/src/nvim/os/time.h index 8c73fc0c3b..b21808307f 100644 --- a/src/nvim/os/time.h +++ b/src/nvim/os/time.h @@ -3,6 +3,7 @@ #include <stdint.h> #include <stdbool.h> +#include <time.h> #ifdef INCLUDE_GENERATED_DECLARATIONS # include "os/time.h.generated.h" |