如何以纳秒精度检索文件时间?
我刚刚发现 stat()
调用和相应的 struct stat
不包含精度大于一秒的文件时间字段。有多种 {f,l}utime{n,}s()
函数可以设置这些时间,但不能获取。
那么如何获得纳秒精度的这些时间(最好使用 POSIX API)?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
stat()
本身返回的stat
结构已针对 POSIX.1-2008 进行了升级。struct stat
结构包含三个修改时间,如下所示:(来自 此 OpenGroup 链接这里在< /code>) 至少包含:
标题下,
),并且struct timespec
在那里定义(在以前,这三个时间是
time_t
值,分辨率为一秒。The
stat
structure returned bystat()
itself has been upgraded for POSIX.1-2008.The
struct stat
structure contains the three modification times as:(from this OpenGroup link here under
Headers, <sys/stat.h>
) and thatstruct timespec
is defined there (in<time.h>
) as containing at least:Previously, these three times were
time_t
values with their one-second resolution.大多数文件系统不保存如此准确的时间戳。来自此处:
Most file systems dont hold such accurate timestamps. From here: