Skip to content

Commit cdb1ef0

Browse files
committed
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)
2 parents f879501 + 370ddcb commit cdb1ef0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

git-compat-util.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,25 @@ static inline const char *precompose_string_if_needed(const char *in)
339339
int compat_mkdir_wo_trailing_slash(const char*, mode_t);
340340
#endif
341341

342+
#ifdef time
343+
#undef time
344+
#endif
345+
static inline time_t git_time(time_t *tloc)
346+
{
347+
struct timeval tv;
348+
349+
/*
350+
* Avoid time(NULL), which can disagree with gettimeofday(2)
351+
* and filesystem timestamps.
352+
*/
353+
gettimeofday(&tv, NULL);
354+
355+
if (tloc)
356+
*tloc = tv.tv_sec;
357+
return tv.tv_sec;
358+
}
359+
#define time git_time
360+
342361
#ifdef NO_STRUCT_ITIMERVAL
343362
struct itimerval {
344363
struct timeval it_interval;

0 commit comments

Comments
 (0)