From f030c24257d48c71fd11eb2bc4c00224d2970d34 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 25 Mar 2015 14:16:45 +0000 Subject: mingw: changes to handling of directory permissions The read-only attribute on a directory in Microsoft Windows is quite different from write permission in POSIX. Modify rmdir(2) and chmod(2) to provide more POSIX-like behaviour: rmdir will remove a directory even if it's read-only chmod won't make a directory read-only --- win32/mingw.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'win32') diff --git a/win32/mingw.c b/win32/mingw.c index fe45589c2..d76f17820 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -842,6 +842,19 @@ int mingw_mkdir(const char *path, int mode UNUSED_PARAM) return ret; } +#undef chmod +int mingw_chmod(const char *path, int mode) +{ + WIN32_FILE_ATTRIBUTE_DATA fdata; + + if ( get_file_attr(path, &fdata) == 0 && + fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { + mode |= 0222; + } + + return chmod(path, mode); +} + int fcntl(int fd, int cmd, ...) { va_list arg; @@ -1014,6 +1027,14 @@ int mingw_access(const char *name, int mode) return -1; } +#undef rmdir +int mingw_rmdir(const char *path) +{ + /* read-only directories cannot be removed */ + chmod(path, 0666); + return rmdir(path); +} + /* check if path can be made into an executable by adding a suffix; * return an allocated string containing the path if it can; * return NULL if not. -- cgit v1.2.3-55-g6feb