Skip to content

Commit 6ad89b7

Browse files
committed
uuid: timespec_now for windows and android
1 parent 5f0a1d2 commit 6ad89b7

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/uuid/extension.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@
6767
#include <string.h>
6868
#include <time.h>
6969

70-
// Some older systems do not support timespec_get() from time.h
71-
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || \
70+
// Some platforms do not support timespec_get() from time.h.
71+
#if defined(_WIN32)
72+
#include <sys/timeb.h>
73+
#elif !defined(__STDC_VERSION__) || __STDC_VERSION__ < 201112L || \
7274
(!defined(TIME_UTC) && (!defined(_POSIX_TIMERS) || _POSIX_TIMERS <= 0))
7375
#include <sys/time.h>
7476
#endif
@@ -83,11 +85,21 @@ SQLITE_EXTENSION_INIT3
8385
// timespec_now returns the current time with nanosecond precision.
8486
static struct timespec timespec_now(void) {
8587
struct timespec ts;
86-
#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && defined(TIME_UTC)
87-
timespec_get(&ts, TIME_UTC);
88+
#if defined(_WIN32)
89+
// Windows.
90+
struct __timeb64 tb;
91+
_ftime64(&tb);
92+
ts.tv_sec = (time_t)tb.time;
93+
ts.tv_nsec = tb.millitm * 1000000;
8894
#elif defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
95+
// POSIX.
8996
clock_gettime(CLOCK_REALTIME, &ts);
97+
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && defined(TIME_UTC) && \
98+
!defined(__ANDROID__)
99+
// C11.
100+
timespec_get(&ts, TIME_UTC);
90101
#else
102+
// Fallback for older systems.
91103
struct timeval tv;
92104
gettimeofday(&tv, NULL);
93105
ts.tv_sec = tv.tv_sec;

0 commit comments

Comments
 (0)