summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-01-05 01:50:06 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-01-05 01:50:06 +0000
commitfb6174380ad0a4e6cfbd73fe5adb4b119d40a97b (patch)
tree71600e1c80ab130129ea46db52408a98cffc8cd7
parentc5fd81c5e53b5c4b0db5e55c3614a373ac7cef0a (diff)
downloadruby-fb6174380ad0a4e6cfbd73fe5adb4b119d40a97b.tar.gz
ruby-fb6174380ad0a4e6cfbd73fe5adb4b119d40a97b.tar.xz
ruby-fb6174380ad0a4e6cfbd73fe5adb4b119d40a97b.zip
* dir.c (dir_s_mkdir): win32 special processing doesn't need any
longer. (backported from CVS HEAD) * win32/win32.[ch] (rb_w32_mkdir): new function. POSIX.1 compatible interface. (backported from CVS HEAD) * win32/win32.[ch] (rb_w32_rmdir): new function. (backported from CVS HEAD) git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@7727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--dir.c5
-rw-r--r--win32/win32.c39
-rw-r--r--win32/win32.h6
4 files changed, 56 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 7b6793075..02698e5a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Wed Jan 5 10:48:16 2005 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * dir.c (dir_s_mkdir): win32 special processing doesn't need any
+ longer. (backported from CVS HEAD)
+
+ * win32/win32.[ch] (rb_w32_mkdir): new function. POSIX.1 compatible
+ interface. (backported from CVS HEAD)
+
+ * win32/win32.[ch] (rb_w32_rmdir): new function. (backported from CVS
+ HEAD)
+
Wed Jan 5 02:30:11 2005 Tanaka Akira <akr@m17n.org>
* random.c (init_by_array): imported from mt19937ar-cok.tgz.
diff --git a/dir.c b/dir.c
index 97b78cb2d..d60c0fad2 100644
--- a/dir.c
+++ b/dir.c
@@ -761,13 +761,8 @@ dir_s_mkdir(argc, argv, obj)
}
check_dirname(&path);
-#ifndef _WIN32
if (mkdir(RSTRING(path)->ptr, mode) == -1)
rb_sys_fail(RSTRING(path)->ptr);
-#else
- if (mkdir(RSTRING(path)->ptr) == -1)
- rb_sys_fail(RSTRING(path)->ptr);
-#endif
return INT2FIX(0);
}
diff --git a/win32/win32.c b/win32/win32.c
index 28eb4fc73..20d32d57c 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -3324,6 +3324,45 @@ rb_w32_snprintf(char *buf, size_t size, const char *format, ...)
return ret;
}
+#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;
+}
+
#if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
int
rb_w32_isatty(int fd)
diff --git a/win32/win32.h b/win32/win32.h
index 8d3284948..a4e5ab20d 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -127,6 +127,10 @@ extern "C++" {
#undef isatty
#define isatty(h) rb_w32_isatty(h)
#endif
+#undef mkdir
+#define mkdir(p, m) rb_w32_mkdir(p, m)
+#undef rmdir
+#define rmdir(p) rb_w32_rmdir(p)
#ifdef __MINGW32__
struct timezone {
@@ -187,6 +191,8 @@ extern pid_t rb_w32_getpid(void);
#if !defined(__BORLANDC__) && !defined(_WIN32_WCE)
extern int rb_w32_isatty(int);
#endif
+extern int rb_w32_mkdir(const char *, int);
+extern int rb_w32_rmdir(const char *);
#ifdef __BORLANDC__
extern FILE *rb_w32_fopen(const char *, const char *);