views:

106

answers:

2

I am using RHEL 4

i am using syscall stat as follows:-

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"

That means i get error as "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?

+1  A: 

Does it give you any meaningful error message if you call it like this?

   if (stat("file", &stat_obj) == -1) {
       perror("stat");
   }
Lars Haugseth
i did strerror (errno) but it returns Success
anish
+1  A: 

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.

Also ensure that you #include <errno.h>, and are not declaring errno yourself, especially if your program is multithreaded. errno is a per-thread variable so if you declare it as a global you can get the wrong one. (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.)

mark4o
All good suggestions and probably the best that can be done in the absence of more information.
Duck