summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-08-09 23:26:25 -0400
committerTavian Barnes <tavianator@tavianator.com>2024-08-09 23:28:55 -0400
commit1507cc211f6ce5b4f20f83470eacf44755a0cdcc (patch)
tree79f204eeb7ebdceeee027297d48d1d59802d3f66 /src/eval.c
parentbaf9ee660c9f1d44d64341e225f9e0d7b808424d (diff)
downloadbfs-1507cc211f6ce5b4f20f83470eacf44755a0cdcc.tar.xz
bfstd: New sysoption() macro to check for POSIX option runtime support
POSIX allows optional features to be supported at compile time but not necessarily at run time by defining _POSIX_OPTION to 0 and requiring users to check sysconf(_SC_OPTION) > 0. The new sysoption() macro simplifies the check. sighook() and bfs_spawn() now check for conditional runtime support for the relevant POSIX options.
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/eval.c b/src/eval.c
index 8ec6908..90d9d37 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1018,12 +1018,15 @@ bool eval_xtype(const struct bfs_expr *expr, struct bfs_eval *state) {
* clock_gettime() wrapper.
*/
static int eval_gettime(struct bfs_eval *state, struct timespec *ts) {
-#if _POSIX_MONOTONIC_CLOCK > 0
- int ret = clock_gettime(CLOCK_MONOTONIC, ts);
-#else
- int ret = clock_gettime(CLOCK_REALTIME, ts);
+ clockid_t clock = CLOCK_REALTIME;
+
+#if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0
+ if (sysoption(MONOTONIC_CLOCK) > 0) {
+ clock = CLOCK_MONOTONIC;
+ }
#endif
+ int ret = clock_gettime(clock, ts);
if (ret != 0) {
bfs_warning(state->ctx, "%pP: clock_gettime(): %s.\n", state->ftwbuf, errstr());
}