]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
_chmod is obsolete on the Borland C environment.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Fri, 18 Dec 2009 18:15:24 +0000 (13:15 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Fri, 18 Dec 2009 18:15:24 +0000 (13:15 -0500)
Use Win32 API instead of _chmod/_wchmod.

SVN-Revision: 1764

libarchive/archive_windows.c

index 393d8e8d24274a421903e563e075f372e8730ea8..f938ca0a9259fa33d95c755580acb44d5f946dd8 100644 (file)
@@ -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);
 }
 
 /*