7bc92346ccafc8ca954332a7fb68163c3e5fea41
[reactos.git] / reactos / lib / crt / io / chmod.c
1
2 #include "precomp.h"
3 #include <io.h>
4 #include <sys/stat.h>
5 #include <tchar.h>
6 #include <internal/file.h>
7
8 #define NDEBUG
9 #include <internal/debug.h>
10
11
12 #define mode_t int
13
14
15 /*
16 * @implemented
17 */
18 int _tchmod(const _TCHAR* filename, mode_t mode)
19 {
20 DWORD FileAttributes = 0;
21 BOOLEAN Set = FALSE;
22
23 DPRINT(#_tchmod"('%"sT"', %x)\n", filename, mode);
24
25 FileAttributes = GetFileAttributes(filename);
26 if ( FileAttributes == (DWORD)-1 ) {
27 _dosmaperr(GetLastError());
28 return -1;
29 }
30
31 if ( mode == 0 )
32 return -1;
33
34 if (mode & _S_IWRITE) {
35 if (FileAttributes & FILE_ATTRIBUTE_READONLY) {
36 FileAttributes &= ~FILE_ATTRIBUTE_READONLY;
37 Set = TRUE;
38 }
39 } else {
40 if (!(FileAttributes & FILE_ATTRIBUTE_READONLY)) {
41 FileAttributes |= FILE_ATTRIBUTE_READONLY;
42 Set = TRUE;
43 }
44 }
45 if (Set && SetFileAttributes(filename, FileAttributes) == FALSE) {
46 _dosmaperr(GetLastError());
47 return -1;
48 }
49 return 0;
50 }