我想在C.文件的最后修改日期几乎所有的来源,我发现沿着这个片段使用的东西:获取文件的最后修改日期用C
char *get_last_modified(char *file) {
struct tm *clock;
struct stat attr;
stat(file, &attr);
clock = gmtime(&(attr.st_mtime));
return asctime(clock);
}
但attr
没有按” t甚至有一个字段st_mtime
,只有st_mtimespec
。然而,当使用这个我的Eclipse告诉我,passing argument 1 of 'gmtime' from incompatible pointer type
就行clock = gmtime(&(attr.st_mtimespec));
我做错了什么?
PS:我开发的OSX雪豹,Eclipse CDT的使用GCC作为跨平台编译器
是的,否则'stat'本身将不可用。 – 2012-07-07 08:55:20
虽然OT:你不想把'get_last_modified()'返回的引用存储起来,不是吗? 'asctime()'返回一个静态内存的引用,它的内容在每次连续调用时都会被覆盖。 – alk 2012-07-07 09:14:02
它只被调用一次,但我会记住应该永远改变:) – 2012-07-07 09:22:53