diff --git a/docs/src/misc.rst b/docs/src/misc.rst index ee819b19..ed84c108 100644 --- a/docs/src/misc.rst +++ b/docs/src/misc.rst @@ -579,7 +579,7 @@ API .. versionadded:: 1.25.0 -.. c:function:: int uv_gettimeofday(uv_timeval_t* tv) +.. c:function:: int uv_gettimeofday(uv_timeval64_t* tv) Cross-platform implementation of :man:`gettimeofday(2)`. The timezone argument to `gettimeofday()` is not supported, as it is considered obsolete. diff --git a/include/uv.h b/include/uv.h index 4a519351..df15b836 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1099,6 +1099,11 @@ typedef struct { long tv_usec; } uv_timeval_t; +typedef struct { + int64_t tv_sec; + int32_t tv_usec; +} uv_timeval64_t; + typedef struct { uv_timeval_t ru_utime; /* user CPU time used */ uv_timeval_t ru_stime; /* system CPU time used */ @@ -1609,7 +1614,7 @@ UV_EXTERN void uv_key_delete(uv_key_t* key); UV_EXTERN void* uv_key_get(uv_key_t* key); UV_EXTERN void uv_key_set(uv_key_t* key, void* value); -UV_EXTERN int uv_gettimeofday(uv_timeval_t* tv); +UV_EXTERN int uv_gettimeofday(uv_timeval64_t* tv); typedef void (*uv_thread_cb)(void* arg); diff --git a/src/unix/core.c b/src/unix/core.c index 96b92e43..e7e9f4b8 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -1431,7 +1431,7 @@ int uv__getsockpeername(const uv_handle_t* handle, return 0; } -int uv_gettimeofday(uv_timeval_t* tv) { +int uv_gettimeofday(uv_timeval64_t* tv) { struct timeval time; if (tv == NULL) @@ -1440,7 +1440,7 @@ int uv_gettimeofday(uv_timeval_t* tv) { if (gettimeofday(&time, NULL) != 0) return UV__ERR(errno); - tv->tv_sec = time.tv_sec; - tv->tv_usec = time.tv_usec; + tv->tv_sec = (int64_t) time.tv_sec; + tv->tv_usec = (int32_t) time.tv_usec; return 0; } diff --git a/src/win/util.c b/src/win/util.c index 129d4b95..2c107284 100644 --- a/src/win/util.c +++ b/src/win/util.c @@ -1779,7 +1779,7 @@ error: return r; } -int uv_gettimeofday(uv_timeval_t* tv) { +int uv_gettimeofday(uv_timeval64_t* tv) { /* Based on https://doxygen.postgresql.org/gettimeofday_8c_source.html */ const uint64_t epoch = (uint64_t) 116444736000000000ULL; FILETIME file_time; @@ -1791,7 +1791,7 @@ int uv_gettimeofday(uv_timeval_t* tv) { GetSystemTimeAsFileTime(&file_time); ularge.LowPart = file_time.dwLowDateTime; ularge.HighPart = file_time.dwHighDateTime; - tv->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L); - tv->tv_usec = (long) (((ularge.QuadPart - epoch) % 10000000L) / 10); + tv->tv_sec = (int64_t) ((ularge.QuadPart - epoch) / 10000000L); + tv->tv_usec = (int32_t) (((ularge.QuadPart - epoch) % 10000000L) / 10); return 0; } diff --git a/test/test-gettimeofday.c b/test/test-gettimeofday.c index af8736a5..4ebc11f9 100644 --- a/test/test-gettimeofday.c +++ b/test/test-gettimeofday.c @@ -23,7 +23,7 @@ #include "task.h" TEST_IMPL(gettimeofday) { - uv_timeval_t tv; + uv_timeval64_t tv; int r; tv.tv_sec = 0;