xref: /freebsd/contrib/libfido2/openbsd-compat/clock_gettime.c (revision 2ccfa855b2fc331819953e3de1b1c15ce5b95a7e)
10afa8e06SEd Maste /*
20afa8e06SEd Maste  * Copyright (c) 2020 Yubico AB. All rights reserved.
30afa8e06SEd Maste  * Use of this source code is governed by a BSD-style
40afa8e06SEd Maste  * license that can be found in the LICENSE file.
5*2ccfa855SEd Maste  * SPDX-License-Identifier: BSD-2-Clause
60afa8e06SEd Maste  */
70afa8e06SEd Maste 
80afa8e06SEd Maste #include "openbsd-compat.h"
90afa8e06SEd Maste 
100afa8e06SEd Maste #if !defined(HAVE_CLOCK_GETTIME)
110afa8e06SEd Maste 
120afa8e06SEd Maste #if _WIN32
130afa8e06SEd Maste int
clock_gettime(clockid_t clock_id,struct timespec * tp)140afa8e06SEd Maste clock_gettime(clockid_t clock_id, struct timespec *tp)
150afa8e06SEd Maste {
160afa8e06SEd Maste 	ULONGLONG ms;
170afa8e06SEd Maste 
180afa8e06SEd Maste 	if (clock_id != CLOCK_MONOTONIC) {
190afa8e06SEd Maste 		errno = EINVAL;
200afa8e06SEd Maste 		return (-1);
210afa8e06SEd Maste 	}
220afa8e06SEd Maste 
230afa8e06SEd Maste 	ms = GetTickCount64();
240afa8e06SEd Maste 	tp->tv_sec = ms / 1000L;
250afa8e06SEd Maste 	tp->tv_nsec = (ms % 1000L) * 1000000L;
260afa8e06SEd Maste 
270afa8e06SEd Maste 	return (0);
280afa8e06SEd Maste }
290afa8e06SEd Maste #else
300afa8e06SEd Maste #error "please provide an implementation of clock_gettime() for your platform"
310afa8e06SEd Maste #endif /* _WIN32 */
320afa8e06SEd Maste 
330afa8e06SEd Maste #endif /* !defined(HAVE_CLOCK_GETTIME) */
34