xref: /freebsd/lib/libc/gen/timespec_getres.c (revision 9b5d724cad10087e34165199e55f15f2df744ed5)
1 /*-
2  * Copyright (c) 2023 Dag-Erling Smørgrav
3  *
4  * SPDX-License-Identifier: BSD-2-Clause
5  */
6 
7 #include <time.h>
8 
9 int
timespec_getres(struct timespec * ts,int base)10 timespec_getres(struct timespec *ts, int base)
11 {
12 
13 	switch (base) {
14 	case TIME_UTC:
15 		if (clock_getres(CLOCK_REALTIME, ts) == 0)
16 			return (base);
17 		break;
18 	case TIME_MONOTONIC:
19 		if (clock_getres(CLOCK_MONOTONIC, ts) == 0)
20 			return (base);
21 		break;
22 	}
23 	return (0);
24 }
25