branch update for HEAD-2003021201
[reactos.git] / lib / crtdll / io / chmod.c
1 #include <windows.h>
2 #include <msvcrt/io.h>
3
4 #define NDEBUG
5 #include <msvcrt/msvcrtdbg.h>
6
7 #define mode_t int
8
9
10 int _chmod(const char* filename, mode_t mode)
11 {
12     DWORD FileAttributes = 0;
13     DPRINT("_chmod('%s', %x)\n", filename, mode);
14
15     FileAttributes = GetFileAttributesA(filename);
16     if ( FileAttributes == -1 )
17         return -1;
18
19     if ( mode == 0 )
20         return -1;
21
22     if ((mode & _S_IREAD) == _S_IREAD && (mode & _S_IWRITE) != _S_IWRITE)
23         FileAttributes &= FILE_ATTRIBUTE_READONLY;
24     else if (((mode & _S_IREAD) != _S_IREAD) && ((mode & _S_IWRITE) == _S_IWRITE))
25         FileAttributes &= FILE_ATTRIBUTE_NORMAL;
26     else
27         FileAttributes &= FILE_ATTRIBUTE_NORMAL;
28
29     if (SetFileAttributesA(filename, FileAttributes) == FALSE)
30         return -1;
31
32     return 1;
33 }