我想在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