diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-08-09 23:20:06 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-08-09 23:20:06 -0400 |
commit | baf9ee660c9f1d44d64341e225f9e0d7b808424d (patch) | |
tree | dd77e67044ce5cca653306d48569bdfbbc81e91d | |
parent | 9c74802117d97bdb55be08a954319e1b8733cb9d (diff) | |
download | bfs-baf9ee660c9f1d44d64341e225f9e0d7b808424d.tar.xz |
xtime: Remove xgettime()
clock_gettime() is available everywhere by now.
-rw-r--r-- | src/ctx.c | 2 | ||||
-rw-r--r-- | src/eval.c | 19 | ||||
-rw-r--r-- | src/xtime.c | 14 | ||||
-rw-r--r-- | src/xtime.h | 10 | ||||
-rw-r--r-- | tests/xtouch.c | 4 |
5 files changed, 10 insertions, 39 deletions
@@ -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; } @@ -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 diff --git a/tests/xtouch.c b/tests/xtouch.c index 427e3e0..8660ea5 100644 --- a/tests/xtouch.c +++ b/tests/xtouch.c @@ -247,8 +247,8 @@ int main(int argc, char *argv[]) { times[1] = times[0]; } else { // Don't use UTIME_NOW, so that multiple paths all get the same timestamp - if (xgettime(×[0]) != 0) { - perror("xgettime()"); + if (clock_gettime(CLOCK_REALTIME, ×[0]) != 0) { + perror("clock_gettime()"); return EXIT_FAILURE; } times[1] = times[0]; |