- Fixed _chmod and _wchmod.

svn path=/trunk/; revision=9236
This commit is contained in:
Hartmut Birr 2004-04-28 20:20:00 +00:00
parent 47b812dde4
commit e9ee16d561
2 changed files with 39 additions and 27 deletions

View file

@ -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;
}

View file

@ -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 (SetFileAttributesW(filename, FileAttributes) == FALSE) {
_dosmaperr(GetLastError());
return -1;
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;
}
}
return 1;
if (Set && SetFileAttributesW(filename, FileAttributes) == FALSE) {
_dosmaperr(GetLastError());
return -1;
}
return 0;
}