1135446Strhodes/*
2218384Sdougb * Copyright (c) 2020 Yubico AB. All rights reserved.
3135446Strhodes * Use of this source code is governed by a BSD-style
4135446Strhodes * license that can be found in the LICENSE file.
5193149Sdougb * SPDX-License-Identifier: BSD-2-Clause
6135446Strhodes */
7135446Strhodes
8135446Strhodes#include "openbsd-compat.h"
9135446Strhodes
10135446Strhodes#if !defined(HAVE_CLOCK_GETTIME)
11135446Strhodes
12135446Strhodes#if _WIN32
13135446Strhodesint
14135446Strhodesclock_gettime(clockid_t clock_id, struct timespec *tp)
15135446Strhodes{
16135446Strhodes	ULONGLONG ms;
17135446Strhodes
18218384Sdougb	if (clock_id != CLOCK_MONOTONIC) {
19135446Strhodes		errno = EINVAL;
20170222Sdougb		return (-1);
21170222Sdougb	}
22135446Strhodes
23135446Strhodes	ms = GetTickCount64();
24135446Strhodes	tp->tv_sec = ms / 1000L;
25170222Sdougb	tp->tv_nsec = (ms % 1000L) * 1000000L;
26135446Strhodes
27135446Strhodes	return (0);
28135446Strhodes}
29135446Strhodes#else
30170222Sdougb#error "please provide an implementation of clock_gettime() for your platform"
31135446Strhodes#endif /* _WIN32 */
32135446Strhodes
33170222Sdougb#endif /* !defined(HAVE_CLOCK_GETTIME) */
34135446Strhodes