ea21c21e10974a3ea5ad53e02fc513d0bc341e24
[reactos.git] / reactos / lib / crt / io / access.c
1 #include "precomp.h"
2 #include <io.h>
3 #include <errno.h>
4 #include <tchar.h>
5 #include <internal/file.h>
6
7 #define NDEBUG
8 #include <internal/debug.h>
9
10 #ifdef _UNICODE
11 #define _TS S
12 #else
13 #define _TS s
14 #endif
15
16
17 /*
18 * @implemented
19 */
20 int _taccess( const _TCHAR *_path, int _amode )
21 {
22 DWORD Attributes = GetFileAttributes(_path);
23 DPRINT(MK_STR(_taccess)"('%"_TS"', %x)\n", _path, _amode);
24
25 if (Attributes == -1) {
26 _dosmaperr(GetLastError());
27 return -1;
28 }
29 if ((_amode & W_OK) == W_OK) {
30 if ((Attributes & FILE_ATTRIBUTE_READONLY) == FILE_ATTRIBUTE_READONLY) {
31 __set_errno(EACCES);
32 return -1;
33 }
34 }
35
36 return 0;
37 }
38
39
40
41 /*
42 * INTERNAL
43 */
44 int access_dirT(const _TCHAR *_path)
45 {
46 DWORD Attributes = GetFileAttributes(_path);
47 DPRINT(MK_STR(is_dirT)"('%"_TS"')\n", _path);
48
49 if (Attributes == -1) {
50 _dosmaperr(GetLastError());
51 return -1;
52 }
53
54 if ((Attributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
55 {
56 __set_errno(EACCES);
57 return -1;
58 }
59
60 return 0;
61 }
62