summaryrefslogtreecommitdiff
path: root/openbsd-compat/clock_gettime.c
diff options
context:
space:
mode:
Diffstat (limited to 'openbsd-compat/clock_gettime.c')
-rw-r--r--openbsd-compat/clock_gettime.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/openbsd-compat/clock_gettime.c b/openbsd-compat/clock_gettime.c
new file mode 100644
index 0000000..ca261a6
--- /dev/null
+++ b/openbsd-compat/clock_gettime.c
@@ -0,0 +1,32 @@
1/*
2 * Copyright (c) 2020 Yubico AB. All rights reserved.
3 * Use of this source code is governed by a BSD-style
4 * license that can be found in the LICENSE file.
5 */
6
7#include "openbsd-compat.h"
8
9#if !defined(HAVE_CLOCK_GETTIME)
10
11#if _WIN32
12int
13clock_gettime(clockid_t clock_id, struct timespec *tp)
14{
15 ULONGLONG ms;
16
17 if (clock_id != CLOCK_MONOTONIC) {
18 errno = EINVAL;
19 return (-1);
20 }
21
22 ms = GetTickCount64();
23 tp->tv_sec = ms / 1000L;
24 tp->tv_nsec = (ms % 1000L) * 1000000L;
25
26 return (0);
27}
28#else
29#error "please provide an implementation of clock_gettime() for your platform"
30#endif /* _WIN32 */
31
32#endif /* !defined(HAVE_CLOCK_GETTIME) */