如何以纳秒精度检索文件时间?

发布于 2024-09-12 19:06:01 字数 175 浏览 4 评论 0原文

我刚刚发现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葬花如无物 2024-09-19 19:06:01

stat() 本身返回的 stat 结构已针对 POSIX.1-2008 进行了升级。

struct stat 结构包含三个修改时间,如下所示:(

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.

来自 此 OpenGroup 链接这里标题下,),并且struct timespec在那里定义(在< /code>) 至少包含:

time_t  tv_sec          - Seconds. 
long    tv_nsec         - Nanoseconds. 

以前,这三个时间是 time_t 值,分辨率为一秒。

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.

不离久伴 2024-09-19 19:06:01

大多数文件系统不保存如此准确的时间戳。来自此处

大多数文件系统,包括 ext3,
包括时间戳数据
精确到秒。 Ext4 扩展了
该数据的精确度达到纳秒。
一些消息来源还表明,
ext4 时间戳支持日期至
2514 年 4 月 25 日与 1 月 18 日相比,
2038,对于 ext3

Most file systems dont hold such accurate timestamps. From here:

Most file systems, including ext3,
include timestamp data that is
accurate to a second. Ext4 extends the
accuracy of this data to a nanosecond.
Some sources also indicate that the
ext4 timestamps support dates through
April 25, 2514, versus January 18,
2038, for ext3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文