统计不工作

cha*_*m15 2 c c++ macos

我正在编写一个文件观察器,并且由于某种原因无法获取文件信息,为什么?


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
}
Run Code Online (Sandbox Code Playgroud)

oua*_*uah 5

int result = fstat(fd, &info);
if (!result){
    exit(-1);
}
Run Code Online (Sandbox Code Playgroud)

检查fstat手册页,成功时返回 0。