我想获取 C 语言中文件的最后修改日期。我发现的几乎所有来源都使用以下代码片段中的内容:
char *get_last_modified(char *file) {
struct tm *clock;
struct stat attr;
stat(file, &attr);
clock = gmtime(&(attr.st_mtime));
return asctime(clock);
}
But the attr
甚至没有字段st_mtime
, only st_mtimespec
。然而,当使用这个时,我的 Eclipse 告诉我passing argument 1 of 'gmtime' from incompatible pointer type
在线上clock = gmtime(&(attr.st_mtimespec));
我究竟做错了什么?
PS:我正在 OSX Snow Leopard、Eclipse CDT 上进行开发,并使用 GCC 作为跨平台编译器
在 OS X 上,st_mtimespec.tv_sec
相当于st_mtime
.
为了使其便携,请执行以下操作
#ifdef __APPLE__
#ifndef st_mtime
#define st_mtime st_mtimespec.tv_sec
#endif
#endif
然后使用st_mtime
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)