errno
will only by set if stat()
failed.
So modifiy your code like this:
int result = stat(path, &rd_perm); /* path contains the full path to the original file request */
if ((-1 == result) && (errno == EACCES)) { /* We don't have permissions to view the file... */
Each process has its own instance of errno
.
If going multihreaded make sure to compile using option -pthread
to have errno
being declared as thread-local.
Please note that the compiler option -pthread
is different from telling the linker to link against libpthread
by giving the linker-option -lpthread
.