[英]stat systecall in linux returning error
I am using RHEL 4 我正在使用RHEL 4
i am using syscall stat as follows:- 我正在使用syscall统计信息,如下所示:
if (stat ("file",&stat_obj)){
if (errno == ENOENT){
printf("File not found");
}else{
printf("Unexpected error occured %d ",errno);
}
}
sometimes i get error message as ""Unexpected error occured 0" 有时我会收到错误消息,例如““发生意外错误0”
That means i get error as "0" . 那意味着我得到错误为“ 0”。 i checked file permissions that are ok 我检查了可以的文件权限
what does that mean? 这意味着什么? I am not able to understand why sometimes this is happening ? 我不明白为什么有时会发生这种情况?
Any suggestions? 有什么建议么?
Does it give you any meaningful error message if you call it like this? 如果您这样称呼它,它会给您任何有意义的错误信息吗?
if (stat("file", &stat_obj) == -1) {
perror("stat");
}
Do you have a signal handler in your program? 您的程序中是否有信号处理程序? If so, and it may affect errno
, then make sure that it saves errno
on entry and restores it to its original value before returning. 如果是这样,则可能会影响errno
,然后确保在输入时保存errno
并在返回之前将其恢复为原始值。
Also ensure that you #include <errno.h>
, and are not declaring errno
yourself, especially if your program is multithreaded. 还要确保您#include <errno.h>
,并且不要自己声明errno
,特别是如果您的程序是多线程的。 errno
is a per-thread variable so if you declare it as a global you can get the wrong one. errno
是每个线程的变量,因此,如果将其声明为全局变量,则会得到错误的变量。 (On some platforms you sometimes also need a special compilation flag like -D_TS_ERRNO
for thread-safe errno, but no such flag is needed on Linux.) (在某些平台上,有时对于线程安全的errno,还需要一个特殊的编译标志,例如-D_TS_ERRNO
,但在Linux上则不需要这样的标志。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.