diff options
author | Ron Yorston <rmy@pobox.com> | 2015-03-25 14:16:45 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2015-03-25 14:16:45 +0000 |
commit | f030c24257d48c71fd11eb2bc4c00224d2970d34 (patch) | |
tree | 923bc8828cc0abeeb284f8cc96f9a54bffe2e425 | |
parent | 15efec6ad51f5292a5f4d7b314219125d69e9acb (diff) | |
download | busybox-w32-f030c24257d48c71fd11eb2bc4c00224d2970d34.tar.gz busybox-w32-f030c24257d48c71fd11eb2bc4c00224d2970d34.tar.bz2 busybox-w32-f030c24257d48c71fd11eb2bc4c00224d2970d34.zip |
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
-rw-r--r-- | include/mingw.h | 5 | ||||
-rw-r--r-- | win32/mingw.c | 21 |
2 files changed, 26 insertions, 0 deletions
diff --git a/include/mingw.h b/include/mingw.h index 137548ad8..247aae587 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
@@ -257,7 +257,10 @@ NOIMPL(mingw_bind,SOCKET s UNUSED_PARAM,const struct sockaddr* sa UNUSED_PARAM,i | |||
257 | IMPL(fchmod,int,0,int fildes UNUSED_PARAM, mode_t mode UNUSED_PARAM); | 257 | IMPL(fchmod,int,0,int fildes UNUSED_PARAM, mode_t mode UNUSED_PARAM); |
258 | NOIMPL(fchown,int fd UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM); | 258 | NOIMPL(fchown,int fd UNUSED_PARAM, uid_t uid UNUSED_PARAM, gid_t gid UNUSED_PARAM); |
259 | int mingw_mkdir(const char *path, int mode); | 259 | int mingw_mkdir(const char *path, int mode); |
260 | int mingw_chmod(const char *path, int mode); | ||
261 | |||
260 | #define mkdir mingw_mkdir | 262 | #define mkdir mingw_mkdir |
263 | #define chmod mingw_chmod | ||
261 | 264 | ||
262 | #if ENABLE_LFS | 265 | #if ENABLE_LFS |
263 | # define off_t off64_t | 266 | # define off_t off64_t |
@@ -395,12 +398,14 @@ NOIMPL(ttyname_r,int fd UNUSED_PARAM, char *buf UNUSED_PARAM, int sz UNUSED_PARA | |||
395 | int mingw_unlink(const char *pathname); | 398 | int mingw_unlink(const char *pathname); |
396 | NOIMPL(vfork,void); | 399 | NOIMPL(vfork,void); |
397 | int mingw_access(const char *name, int mode); | 400 | int mingw_access(const char *name, int mode); |
401 | int mingw_rmdir(const char *name); | ||
398 | 402 | ||
399 | #define dup2 mingw_dup2 | 403 | #define dup2 mingw_dup2 |
400 | #define getcwd mingw_getcwd | 404 | #define getcwd mingw_getcwd |
401 | #define lchown chown | 405 | #define lchown chown |
402 | #define open mingw_open | 406 | #define open mingw_open |
403 | #define unlink mingw_unlink | 407 | #define unlink mingw_unlink |
408 | #define rmdir mingw_rmdir | ||
404 | 409 | ||
405 | #undef access | 410 | #undef access |
406 | #define access mingw_access | 411 | #define access mingw_access |
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) | |||
842 | return ret; | 842 | return ret; |
843 | } | 843 | } |
844 | 844 | ||
845 | #undef chmod | ||
846 | int mingw_chmod(const char *path, int mode) | ||
847 | { | ||
848 | WIN32_FILE_ATTRIBUTE_DATA fdata; | ||
849 | |||
850 | if ( get_file_attr(path, &fdata) == 0 && | ||
851 | fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { | ||
852 | mode |= 0222; | ||
853 | } | ||
854 | |||
855 | return chmod(path, mode); | ||
856 | } | ||
857 | |||
845 | int fcntl(int fd, int cmd, ...) | 858 | int fcntl(int fd, int cmd, ...) |
846 | { | 859 | { |
847 | va_list arg; | 860 | va_list arg; |
@@ -1014,6 +1027,14 @@ int mingw_access(const char *name, int mode) | |||
1014 | return -1; | 1027 | return -1; |
1015 | } | 1028 | } |
1016 | 1029 | ||
1030 | #undef rmdir | ||
1031 | int mingw_rmdir(const char *path) | ||
1032 | { | ||
1033 | /* read-only directories cannot be removed */ | ||
1034 | chmod(path, 0666); | ||
1035 | return rmdir(path); | ||
1036 | } | ||
1037 | |||
1017 | /* check if path can be made into an executable by adding a suffix; | 1038 | /* check if path can be made into an executable by adding a suffix; |
1018 | * return an allocated string containing the path if it can; | 1039 | * return an allocated string containing the path if it can; |
1019 | * return NULL if not. | 1040 | * return NULL if not. |