From baf9ee660c9f1d44d64341e225f9e0d7b808424d Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 9 Aug 2024 23:20:06 -0400 Subject: xtime: Remove xgettime() clock_gettime() is available everywhere by now. --- src/ctx.c | 2 +- src/eval.c | 19 +++++++------------ src/xtime.c | 14 -------------- src/xtime.h | 10 ---------- 4 files changed, 8 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/ctx.c b/src/ctx.c index 8fafb32..b33e0e3 100644 --- a/src/ctx.c +++ b/src/ctx.c @@ -71,7 +71,7 @@ struct bfs_ctx *bfs_ctx_new(void) { goto fail; } - if (xgettime(&ctx->now) != 0) { + if (clock_gettime(CLOCK_REALTIME, &ctx->now) != 0) { goto fail; } diff --git a/src/eval.c b/src/eval.c index 7c814ed..8ec6908 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1014,25 +1014,20 @@ bool eval_xtype(const struct bfs_expr *expr, struct bfs_eval *state) { } } -#if _POSIX_MONOTONIC_CLOCK > 0 -# define BFS_CLOCK CLOCK_MONOTONIC -#elif _POSIX_TIMERS > 0 -# define BFS_CLOCK CLOCK_REALTIME -#endif - /** - * Call clock_gettime(), if available. + * clock_gettime() wrapper. */ static int eval_gettime(struct bfs_eval *state, struct timespec *ts) { -#ifdef BFS_CLOCK - int ret = clock_gettime(BFS_CLOCK, ts); +#if _POSIX_MONOTONIC_CLOCK > 0 + int ret = clock_gettime(CLOCK_MONOTONIC, ts); +#else + int ret = clock_gettime(CLOCK_REALTIME, ts); +#endif + if (ret != 0) { bfs_warning(state->ctx, "%pP: clock_gettime(): %s.\n", state->ftwbuf, errstr()); } return ret; -#else - return -1; -#endif } /** diff --git a/src/xtime.c b/src/xtime.c index 186651b..df8fd61 100644 --- a/src/xtime.c +++ b/src/xtime.c @@ -350,17 +350,3 @@ invalid: error: return -1; } - -int xgettime(struct timespec *result) { -#if _POSIX_TIMERS > 0 - return clock_gettime(CLOCK_REALTIME, result); -#else - struct timeval tv; - int ret = gettimeofday(&tv, NULL); - if (ret == 0) { - result->tv_sec = tv.tv_sec; - result->tv_nsec = tv.tv_usec * 1000L; - } - return ret; -#endif -} diff --git a/src/xtime.h b/src/xtime.h index fb60ae4..a3547a7 100644 --- a/src/xtime.h +++ b/src/xtime.h @@ -46,14 +46,4 @@ int xtimegm(struct tm *tm, time_t *timep); */ int xgetdate(const char *str, struct timespec *result); -/** - * Get the current time. - * - * @param[out] result - * A pointer to the result. - * @return - * 0 on success, -1 on failure. - */ -int xgettime(struct timespec *result); - #endif // BFS_XTIME_H -- cgit v1.2.3