diff options
author | Junio C Hamano <gitster@pobox.com> | 2023-03-28 20:51:52 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-03-28 20:51:52 +0300 |
commit | cdb1ef07d22c3ca88bf42ecd08c0c24d515c11ef (patch) | |
tree | 321a0fb5930cf43c65d81e28b7e95a19e8fce2b7 /git-compat-util.h | |
parent | f879501ad08b228797f5473092186900828681d5 (diff) | |
parent | 370ddcbc89646c7f53728ec7d1fb87597b52de67 (diff) |
Merge branch 'pe/time-use-gettimeofday'
time(2) on glib 2.31+, especially on Linux, goes out of sync with
higher resolution timers used for gettimeofday(2) and by the
filesystem. Replace all calls to it with a git_time() wrapper and
use gettimeofday(2) in its implementation.
* pe/time-use-gettimeofday:
git-compat-util: use gettimeofday(2) for time(2)
Diffstat (limited to 'git-compat-util.h')
-rw-r--r-- | git-compat-util.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index 1e6592624d..4a200a9fb4 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -339,6 +339,25 @@ static inline const char *precompose_string_if_needed(const char *in) int compat_mkdir_wo_trailing_slash(const char*, mode_t); #endif +#ifdef time +#undef time +#endif +static inline time_t git_time(time_t *tloc) +{ + struct timeval tv; + + /* + * Avoid time(NULL), which can disagree with gettimeofday(2) + * and filesystem timestamps. + */ + gettimeofday(&tv, NULL); + + if (tloc) + *tloc = tv.tv_sec; + return tv.tv_sec; +} +#define time git_time + #ifdef NO_STRUCT_ITIMERVAL struct itimerval { struct timeval it_interval; |