Good to know. I see that gettimeofday() in glibc effectively wraps clock_gettime() (using CLOCK_REALTIME). Is that not guaranteed to be the same syscall as any that might be used for the filesystem? If not, what other clock might be used? It seems pretty inconvenient if filesystem timestamps aren't somewhat guaranteed to be comparable to a known clock.

I was just thinking that, if the current function uses time(), a call to something like clock_gettime would alleviate the problem with the coarse seconds from time(). But it sounds like you're saying it's just generally more accurate to use stat() (which doesn't seem too onerous in this case).

On 8/20/26 22:14, Vincent Lefevre wrote:
On 2026-08-20 17:26:01 -0400, Reed Underwood wrote:
Would it be preferable to just use gettimeofday (or another function that
guarantees subsecond precision) and use only the seconds?
gettimeofday is no longer in any standard. It was replaced by
clock_gettime. But anyway, it is not possible to know which clock
is the same as the one used for the filesystem. Since the value
will be compared to st_mtime from stat(), it is better to also
use stat() for the comparison.

Reply via email to