summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/win32/win32.c b/win32/win32.c
index 6dc8fffe4e..6dffaa694f 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3430,6 +3430,45 @@ rb_w32_isatty(int fd)
return 1;
}
+#undef mkdir
+#undef rmdir
+int
+rb_w32_mkdir(const char *path, int mode)
+{
+ int ret = -1;
+ RUBY_CRITICAL(do {
+ if (mkdir(path) == -1)
+ break;
+ if (chmod(path, mode) == -1) {
+ int save_errno = errno;
+ rmdir(path);
+ errno = save_errno;
+ break;
+ }
+ ret = 0;
+ } while (0));
+ return ret;
+}
+
+int
+rb_w32_rmdir(const char *path)
+{
+ DWORD attr;
+ int ret;
+ RUBY_CRITICAL({
+ attr = GetFileAttributes(path);
+ if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
+ attr &= ~FILE_ATTRIBUTE_READONLY;
+ SetFileAttributes(path, attr);
+ }
+ ret = rmdir(path);
+ if (ret < 0 && attr != (DWORD)-1) {
+ SetFileAttributes(path, attr);
+ }
+ });
+ return ret;
+}
+
//
// Fix bcc32's stdio bug
//