freebsd-src/lib/libc/gen/timespec_getres.c
Dag-Erling Smørgrav 9b5d724cad libc: Add timespec_getres(3) as per C23.
This also adds support for TIME_MONOTONIC to timespec_get(3).

Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D41524
2023-08-24 21:31:54 +00:00

25 lines
387 B
C

/*-
* Copyright (c) 2023 Dag-Erling Smørgrav
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <time.h>
int
timespec_getres(struct timespec *ts, int base)
{
switch (base) {
case TIME_UTC:
if (clock_getres(CLOCK_REALTIME, ts) == 0)
return (base);
break;
case TIME_MONOTONIC:
if (clock_getres(CLOCK_MONOTONIC, ts) == 0)
return (base);
break;
}
return (0);
}