【发布时间】:2012-07-07 13:54:43
【问题描述】:
我想在 C 中获取文件的最后修改日期。我发现的几乎所有来源都使用这个 sn-p 中的某些内容:
char *get_last_modified(char *file) {
struct tm *clock;
struct stat attr;
stat(file, &attr);
clock = gmtime(&(attr.st_mtime));
return asctime(clock);
}
但是attr 甚至没有st_mtime 字段,只有st_mtimespec。然而,当使用这个时,我的 Eclipse 告诉我 passing argument 1 of 'gmtime' from incompatible pointer type 在线 clock = gmtime(&(attr.st_mtimespec));
我做错了什么?
PS:我正在 OSX Snow Leopard、Eclipse CDT 上进行开发,并使用 GCC 作为跨平台编译器
【问题讨论】:
-
是的,否则
stat本身将不可用。 -
虽然 OT:您不想存储
get_last_modified()返回的引用,不是吗?asctime()返回对静态内存的引用,其内容将在每次连续调用时被覆盖。 -
它只被调用过一次,但如果它发生变化我会记住它:)
标签: c date file-io compiler-errors