Getting the last modified date of a file in C -


i want last modified date of file in c. sources found use along snippet:

char *get_last_modified(char *file) { struct tm *clock; struct stat attr; stat(file, &attr); clock = gmtime(&(attr.st_mtime)); return asctime(clock); } 

but attr doesn't have field st_mtime, st_mtimespec. yet, when using eclipse tells me passing argument 1 of 'gmtime' incompatible pointer type on line clock = gmtime(&(attr.st_mtimespec));

what doing wrong?

ps: i'm developing on osx snow leopard, eclipse cdt , using gcc cross-platform compiler

on os x, st_mtimespec.tv_sec equivalent of st_mtime.

to make portable, do

#ifdef __apple__ #ifndef st_mtime #define st_mtime st_mtimespec.tv_sec #endif #endif 

and use st_mtime.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -