aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/gen/timespec_getres.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/gen/timespec_getres.c')
-rw-r--r--lib/libc/gen/timespec_getres.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/libc/gen/timespec_getres.c b/lib/libc/gen/timespec_getres.c
new file mode 100644
index 000000000000..4977d22cf910
--- /dev/null
+++ b/lib/libc/gen/timespec_getres.c
@@ -0,0 +1,24 @@
+/*-
+ * 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);
+}