Added debug messages.
[reactos.git] / reactos / 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 #ifndef F_OK
8 #define F_OK 0x01
9 #endif
10 #ifndef R_OK
11 #define R_OK 0x02
12 #endif
13 #ifndef W_OK
14 #define W_OK 0x04
15 #endif
16 #ifndef X_OK
17 #define X_OK 0x08
18 #endif
19 #ifndef D_OK
20 #define D_OK 0x10
21 #endif
22
23 int _access( const char *_path, int _amode )
24 {
25 DWORD Attributes = GetFileAttributesA(_path);
26 DPRINT("_access('%s', %x)\n", _path, _amode);
27
28 if ( Attributes == -1 ) {
29 __set_errno(ENOENT);
30 return -1;
31 }
32
33 if ( (_amode & W_OK) == W_OK ) {
34 if ( (Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY ) {
35 __set_errno(EACCES);
36 return -1;
37 }
38 }
39 if ( (_amode & D_OK) == D_OK ) {
40 if ( (Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ) {
41 __set_errno(EACCES);
42 return -1;
43 }
44 }
45
46 return 0;
47 }
48
49 int _waccess( const wchar_t *_path, int _amode )
50 {
51 DWORD Attributes = GetFileAttributesW(_path);
52
53 if ( Attributes == -1 ) {
54 __set_errno(ENOENT);
55 return -1;
56 }
57
58 if ( (_amode & W_OK) == W_OK ) {
59 if ( (Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY ) {
60 __set_errno(EACCES);
61 return -1;
62 }
63 }
64 if ( (_amode & D_OK) == D_OK ) {
65 if ( (Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY ) {
66 __set_errno(EACCES);
67 return -1;
68 }
69 }
70
71 return 0;
72 }