views:

66

answers:

2

I'm developing a C-program with VS2005 and I found out that when folder access is restricted in a way that I can't create folders or delete anything from a folder the _stat function for the folder does not set errno correctly. errno is set to value ENOENT. I absolutely cannot modify the permissions so I could get value EACCES. Either _stat returns 0 (no error) or the errno is set to ENOENT. Can u tell me how to make distinction between folder really existing and user not having enough permissions for folder? Another thing i don't uderstand is that what particular permission results _stat to return -1. When I look at the Effective permissions of the folder I've been testing _stat with it has nothing in 'Deny'-column. Even 'Create folders / Append data' is checked while i cannot create folders into it.

Thanks & BR -Matti

+1  A: 

I am not100% sure of this, but have you tried _doserrno? According to MSDN documentation:

For I/O operations, use _doserrno to access the operating-system error-code 
equivalents of errno codes. For most non-I/O operations the value of _doserrno is   
undefined.
Javier
+2  A: 

Windows security attributes are too fine grained to test this with _stat(). Its implementation uses the FindFirstFile() API function, that will only fail if the right to enumerate files is not granted. That's rarely the case, the more restrictive one that typically is turned off is Write or Modify.

Hacking the security API to test the ACLs is often avoided and highly unportable. You just find out that you don't have the necessary privilege when you try to open the file. Quite acceptable because there's nothing you can do in your code to gain the right to access the file.

Hans Passant
i must say that i don't understand this. i can go to the folder with Win XP Explorer and see the files. Still _stat set errno to ENOENT. Other question also remains unaswered: "Why the documentation tells about EACCES if errno is never set to that?"
matti
and thanks for your answer!
matti
The MSDN docs for _stat() never mention EACCES. Post repro code to get help with diagnosing ENOENT.
Hans Passant
u're right. i couldn't believe my eyes when i rechecked it today. my bad. thanks.
matti