xref: /freebsd/lib/libc/gen/timespec_getres.c (revision e9ac41698b2f322d55ccf9da50a3596edb2c1800)
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
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