clock_gettime.c revision 1.1.1.1
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) */
33