I've now been googleing this for about two hours, yet I was unable to find any answers that helped.
The definition of 'stat' as spcified in the manpage says that a st_ctime field exists.
struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_t st_mode; /* protection */ nlink_t st_nlink; /* number of hard links */ uid_t st_uid; /* user ID of owner */ gid_t st_gid; /* group ID of owner */ dev_t st_rdev; /* device ID (if special file) */ off_t st_size; /* total size, in bytes */ blksize_t st_blksize; /* blocksize for file system I/O */ blkcnt_t st_blocks; /* number of 512B blocks allocated */ time_t st_atime; /* time of last access */ time_t st_mtime; /* time of last modification */ time_t st_ctime; /* time of last status change */ };
However, this does not seem to be true for my system even though I'm using gcc (which should be behaving according to the standard).
In fact, all of the time fields (atime, mtime, ctime) are missing and therefore the struct contains some atim, mtim and ctim values which return a timespec instead of the desired time_t value.
Now my questions:
- Why is this so? Maybe I included the wrong header but I'm really sure it's gotta be sys/stat.h.
- I have not been finding too much information about timespec, what is it and why is it returned here?
- Even if I find a workaround, does it help m or will any other system fail to execute my code?
I am using Ubuntu 11.10 and gcc 4.6.1.
My code (partly):
struct stat file_info;
time_t t;
if( lstat( path, &file_info ) == 0 ) {
struct tm* timeinfo;
t = file_info.st_ctime;
timeinfo = localtime( &t );
I'd be really glad if you could help with this one, I really got no clue why I can not compile using the st_ctime field of my struct and as usual gcc is not too much of a help when it comes to talking about errors ;-)
Probably it's got to do something with #include problems, but I'm not able to determine what.