reactos/lib/msvcrt/io
diff -u -r1.8 -r1.9
--- chmod.c 3 Dec 2003 17:17:03 -0000 1.8
+++ chmod.c 28 Apr 2004 20:20:00 -0000 1.9
@@ -14,28 +14,33 @@
int _chmod(const char* filename, mode_t mode)
{
DWORD FileAttributes = 0;
+ BOOLEAN Set = FALSE;
+
DPRINT("_chmod('%s', %x)\n", filename, mode);
FileAttributes = GetFileAttributesA(filename);
if ( FileAttributes == -1 ) {
_dosmaperr(GetLastError());
return -1;
- }
+ }
if ( mode == 0 )
return -1;
-
- if ((mode & _S_IREAD) == _S_IREAD && (mode & _S_IWRITE) != _S_IWRITE)
- FileAttributes &= FILE_ATTRIBUTE_READONLY;
- else if (((mode & _S_IREAD) != _S_IREAD) && ((mode & _S_IWRITE) == _S_IWRITE))
- FileAttributes &= FILE_ATTRIBUTE_NORMAL;
- else
- FileAttributes &= FILE_ATTRIBUTE_NORMAL;
-
- if (SetFileAttributesA(filename, FileAttributes) == FALSE) {
- _dosmaperr(GetLastError());
- return -1;
+
+ if (mode & _S_IWRITE) {
+ if (FileAttributes & FILE_ATTRIBUTE_READONLY) {
+ FileAttributes &= ~FILE_ATTRIBUTE_READONLY;
+ Set = TRUE;
}
-
- return 1;
+ } else {
+ if (!(FileAttributes & FILE_ATTRIBUTE_READONLY)) {
+ FileAttributes |= FILE_ATTRIBUTE_READONLY;
+ Set = TRUE;
+ }
+ }
+ if (Set && SetFileAttributesA(filename, FileAttributes) == FALSE) {
+ _dosmaperr(GetLastError());
+ return -1;
+ }
+ return 0;
}
reactos/lib/msvcrt/io
diff -u -r1.3 -r1.4
--- wchmod.c 3 Dec 2003 17:17:03 -0000 1.3
+++ wchmod.c 28 Apr 2004 20:20:00 -0000 1.4
@@ -13,28 +13,35 @@
int _wchmod(const wchar_t* filename, mode_t mode)
{
DWORD FileAttributes = 0;
+ BOOLEAN Set = FALSE;
+
DPRINT("_wchmod('%S', %x)\n", filename, mode);
FileAttributes = GetFileAttributesW(filename);
if ( FileAttributes == -1 ) {
- _dosmaperr(GetLastError());
+ _dosmaperr(GetLastError());
return -1;
- }
+ }
if ( mode == 0 )
return -1;
- if ((mode & _S_IREAD) == _S_IREAD && (mode & _S_IWRITE) != _S_IWRITE)
- FileAttributes &= FILE_ATTRIBUTE_READONLY;
- else if (((mode & _S_IREAD) != _S_IREAD) && ((mode & _S_IWRITE) == _S_IWRITE))
- FileAttributes &= FILE_ATTRIBUTE_NORMAL;
- else
- FileAttributes &= FILE_ATTRIBUTE_NORMAL;
+ if (mode & _S_IWRITE) {
+ if (FileAttributes & FILE_ATTRIBUTE_READONLY) {
+ FileAttributes &= ~FILE_ATTRIBUTE_READONLY;
+ Set = TRUE;
+ }
+ } else {
+ if (!(FileAttributes & FILE_ATTRIBUTE_READONLY)) {
+ FileAttributes |= FILE_ATTRIBUTE_READONLY;
+ Set = TRUE;
+ }
+ }
- if (SetFileAttributesW(filename, FileAttributes) == FALSE) {
- _dosmaperr(GetLastError());
+ if (Set && SetFileAttributesW(filename, FileAttributes) == FALSE) {
+ _dosmaperr(GetLastError());
return -1;
- }
+ }
- return 1;
+ return 0;
}