summaryrefslogtreecommitdiff
path: root/libarchive/archive_windows.c
diff options
context:
space:
mode:
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>2009-12-18 13:15:24 -0500
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>2009-12-18 13:15:24 -0500
commitc54641cd7e51a2689bb7a92cdae74f6bc4e3488d (patch)
tree2b96835ddb647069d21cadddb87b479e9471a813 /libarchive/archive_windows.c
parent4390f15652fde7e58b959c2aaf31852f897a2bf7 (diff)
downloadlibarchive-c54641cd7e51a2689bb7a92cdae74f6bc4e3488d.tar.gz
_chmod is obsolete on the Borland C environment.
Use Win32 API instead of _chmod/_wchmod. SVN-Revision: 1764
Diffstat (limited to 'libarchive/archive_windows.c')
-rw-r--r--libarchive/archive_windows.c44
1 files changed, 34 insertions, 10 deletions
diff --git a/libarchive/archive_windows.c b/libarchive/archive_windows.c
index 393d8e8d..f938ca0a 100644
--- a/libarchive/archive_windows.c
+++ b/libarchive/archive_windows.c
@@ -471,19 +471,43 @@ int
__la_chmod(const char *path, mode_t mode)
{
wchar_t *ws;
- int r;
+ DWORD attr;
+ BOOL r;
- r = _chmod(path, mode);
- if (r >= 0 || errno != ENOENT)
- return (r);
- ws = permissive_name(path);
- if (ws == NULL) {
- errno = EINVAL;
+ ws = NULL;
+ attr = GetFileAttributesA(path);
+ if (attr == (DWORD)-1) {
+ if (GetLastError() != ERROR_FILE_NOT_FOUND) {
+ la_dosmaperr(GetLastError());
+ return (-1);
+ }
+ ws = permissive_name(path);
+ if (ws == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+ attr = GetFileAttributesW(ws);
+ if (attr == (DWORD)-1) {
+ free(ws);
+ la_dosmaperr(GetLastError());
+ return (-1);
+ }
+ }
+ if (mode & _S_IWRITE)
+ attr &= ~FILE_ATTRIBUTE_READONLY;
+ else
+ attr |= FILE_ATTRIBUTE_READONLY;
+ if (ws == NULL)
+ r = SetFileAttributesA(path, attr);
+ else {
+ r = SetFileAttributesW(ws, attr);
+ free(ws);
+ }
+ if (r == 0) {
+ la_dosmaperr(GetLastError());
return (-1);
}
- r = _wchmod(ws, mode);
- free(ws);
- return (r);
+ return (0);
}
/*