47f66cd404c27effe1abcf6e8ce0ebacc316224b
[reactos.git] / lib / crtdll / io / access.c
1 #include <crtdll/io.h>
2 #include <windows.h>
3
4 #ifndef F_OK
5  #define F_OK   0x01
6 #endif
7 #ifndef R_OK
8  #define R_OK   0x02
9 #endif
10 #ifndef W_OK
11  #define W_OK   0x04
12 #endif
13 #ifndef X_OK
14  #define X_OK   0x08
15 #endif
16 #ifndef D_OK
17  #define D_OK   0x10
18 #endif
19
20 int _access( const char *_path, int _amode )
21 {
22         DWORD Attributes = GetFileAttributesA(_path);
23
24         if ( Attributes == -1 )
25                 return -1;
26
27         if ( (_amode & W_OK) == W_OK ) {
28                 if ( (Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY )
29                         return -1;
30         }
31         if ( (_amode & D_OK) == D_OK ) {
32                 if ( (Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY )
33                         return -1;
34         }
35
36         return 0;
37                 
38 }