branch update for HEAD-2003021201
[reactos.git] / lib / msvcrt / io / access.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 _access( const char *_path, int _amode )
9 {
10     DWORD Attributes = GetFileAttributesA(_path);
11     DPRINT("_access('%s', %x)\n", _path, _amode);
12
13     if (Attributes == -1)   {
14         __set_errno(ENOENT);
15         return -1;
16     }
17     if ((_amode & W_OK) == W_OK) {
18         if ((Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY) {
19             __set_errno(EACCES);
20             return -1;
21         }
22     }
23     if ((_amode & D_OK) == D_OK) {
24         if ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY) {
25             __set_errno(EACCES);
26             return -1;
27         }
28     }
29     return 0;
30 }