I've just discovered that the stat()
call, and the corresponding struct stat
, does not contain fields for the file times with precision greater than one second. For setting these times, there are a variety of {f,l}utime{n,}s()
functions, but not for getting.
How then does obtain these times with nanosecond precision, preferably using POSIX API?
The stat
structure returned by stat()
itself has been upgraded for POSIX.1-2008.
The struct stat
structure contains the three modification times as:
struct timespec st_atim - Last data access timestamp.
struct timespec st_mtim - Last data modification timestamp.
struct timespec st_ctim - Last file status change timestamp.
(from this OpenGroup link here under Headers, <sys/stat.h>
) and that struct timespec
is defined there (in <time.h>
) as containing at least:
time_t tv_sec - Seconds.
long tv_nsec - Nanoseconds.
Previously, these three times were time_t
values with their one-second resolution.