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  * SPDX-License-Identifier: BSD-2-Clause
6  */
7 
8 #include "openbsd-compat.h"
9 
10 #if !defined(HAVE_CLOCK_GETTIME)
11 
12 #if _WIN32
13 int
14 clock_gettime(clockid_t clock_id, struct timespec *tp)
15 {
16 	ULONGLONG ms;
17 
18 	if (clock_id != CLOCK_MONOTONIC) {
19 		errno = EINVAL;
20 		return (-1);
21 	}
22 
23 	ms = GetTickCount64();
24 	tp->tv_sec = ms / 1000L;
25 	tp->tv_nsec = (ms % 1000L) * 1000000L;
26 
27 	return (0);
28 }
29 #else
30 #error "please provide an implementation of clock_gettime() for your platform"
31 #endif /* _WIN32 */
32 
33 #endif /* !defined(HAVE_CLOCK_GETTIME) */
34