:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / lib / crtdll / io / chmod.c
1 #include <windows.h>
2 #include <crtdll/io.h>
3 #define mode_t int
4
5 int
6 _chmod(const char *filename, mode_t mode)
7 {
8         DWORD FileAttributes = 0;
9         
10         FileAttributes = GetFileAttributes(filename);
11         if ( FileAttributes == -1 )
12                 return -1;
13                
14         if ( mode == 0 )
15                 return -1;
16         
17         
18         if ( (mode & _S_IREAD) == _S_IREAD && (mode & _S_IWRITE) != _S_IWRITE)
19                 FileAttributes &= FILE_ATTRIBUTE_READONLY;       
20         else if ( ((mode & _S_IREAD) != _S_IREAD) && ((mode & _S_IWRITE) == _S_IWRITE) )
21                 FileAttributes &= FILE_ATTRIBUTE_NORMAL;
22         else
23                 FileAttributes &= FILE_ATTRIBUTE_NORMAL;
24                 
25
26
27         if ( SetFileAttributes(filename,FileAttributes) == FALSE )
28                 return -1;
29
30         return 1;
31 }