Skip to content

Commit

Permalink
xtime: Remove xgettime()
Browse files Browse the repository at this point in the history
clock_gettime() is available everywhere by now.
  • Loading branch information
tavianator committed Aug 10, 2024
1 parent 9c74802 commit baf9ee6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
19 changes: 7 additions & 12 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
14 changes: 0 additions & 14 deletions src/xtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,3 @@ int xgetdate(const char *str, struct timespec *result) {
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
}
10 changes: 0 additions & 10 deletions src/xtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tests/xtouch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(&times[0]) != 0) {
perror("xgettime()");
if (clock_gettime(CLOCK_REALTIME, &times[0]) != 0) {
perror("clock_gettime()");
return EXIT_FAILURE;
}
times[1] = times[0];
Expand Down

0 comments on commit baf9ee6

Please sign in to comment.