update for HEAD-2003021201
[reactos.git] / lib / msvcrt / io / waccess.c
1 #include <windows.h>
2 #include <msvcrt/io.h>
3 #include <msvcrt/errno.h>
4 #define NDEBUG
5 #include <msvcrt/msvcrtdbg.h>
6
7
8 int _waccess(const wchar_t *_path, int _amode)
9 {
10     DWORD Attributes = GetFileAttributesW(_path);
11
12     if (Attributes == -1) {
13         __set_errno(ENOENT);
14         return -1;
15     }
16     if ((_amode & W_OK) == W_OK) {
17         if ((Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY) {
18             __set_errno(EACCES);
19             return -1;
20         }
21     }
22     if ((_amode & D_OK) == D_OK) {
23         if ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) {
24             __set_errno(EACCES);
25             return -1;
26         }
27     }
28     return 0;
29 }