stat not working
stat not working
我正在编写一个文件观察程序,由于某些原因,stat无法获取文件信息,为什么?
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
}
int result = fstat(fd, &info);
if (!result){
exit(-1);
}
检查fstat
手册页,成功时返回0。
stat
在成功时返回零,大多数标准libc函数也是如此。
这是这样设计的,所以你可以很容易地检查库调用链中的错误:
if (stat(fd, &info)) {
perror("stat");
exit(1);
}
//stat succeeded.
if (...) {
}
根据您的用法,我认为您想要fstat()。fstat()使用fd作为参数,stat()使用字符串。
相关文章:
- GDB - strcmp not working: __strcmp_sse2_unaligned
- QT qScriptConnect is not working
- QDesktopServices::openUrl() not working Qt
- "Configure: Error: Could Not Find a Working Compiler, See config.log For Details"
- C++ std::set ordering not working with customer class*
- C++ SetWindowText not working
- visual studio 2012 c++ hello world - iostream not working
- getGravity not working?
- Opencv findcontours CV_RETR_EXTERNAL not working
- c++ srand() not working
- std::queue::empty() not working?
- BCB swprintf not working
- 将类型作为指向另一个类的对象的指针的泛型类-NOT WORKING
- LoadLibrary is not working
- gluUnProject not working
- C++ catch bad_alloc not working
- updatelayeredwindow not working
- OpenMP set_num_threads() is not working
- glOrtho not working
- Cuda atomicInc not working