Reputation: 14251
I am writing a file watcher and stat for some reason cant get a hold of file information, why?
struct stat info;
int fd = open(path, O_EVTONLY);
if (fd <= 0){
exit(-1);
}
int result = fstat(fd, &info);
if (!result){
exit(-1); //This happens! Errno says "No such file or directory" but that cant be because open would've failed
}
Upvotes: 2
Views: 1150
Reputation: 145829
int result = fstat(fd, &info);
if (!result){
exit(-1);
}
Check fstat
man page, on success 0 is returned.
Upvotes: 5
Reputation: 44220
From your usage, I assume you want fstat(). fstat() takes a fd as argument, stat() a string.
Upvotes: 1
Reputation: 137398
stat
returns zero on success, as do most standard libc functions.
This is designed as such, so you can easily check for errors in a chain of library calls:
if (stat(fd, &info)) {
perror("stat");
exit(1);
}
//stat succeeded.
if (...) {
}
Upvotes: 3