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