From 571e1361b656b9949724bf64a14d665cf9d662f8 Mon Sep 17 00:00:00 2001 From: usa Date: Tue, 7 Dec 2004 04:45:46 +0000 Subject: * io.c (dir_s_mkdir): win32 special processing doesn't need any longer. * win32/win32.[ch] (rb_w32_mkdir): new function. POSIX.1 compatible interface. * win32/win32.[ch] (rb_w32_rmdir): new function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7487 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- win32/win32.c | 39 +++++++++++++++++++++++++++++++++++++++ win32/win32.h | 7 +++++++ 2 files changed, 46 insertions(+) (limited to 'win32') 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 // diff --git a/win32/win32.h b/win32/win32.h index 4ca3b299bc..5fe8703d4a 100644 --- a/win32/win32.h +++ b/win32/win32.h @@ -130,6 +130,11 @@ extern "C++" { #undef isatty #define isatty(h) rb_w32_isatty(h) +#undef mkdir +#define mkdir(p, m) rb_w32_mkdir(p, m) +#undef rmdir +#define rmdir(p) rb_w32_rmdir(p) + #ifdef __MINGW32__ struct timezone { int tz_minuteswest; @@ -190,6 +195,8 @@ extern int kill(int, int); extern int fcntl(int, int, ...); extern pid_t rb_w32_getpid(void); extern int rb_w32_isatty(int); +extern int rb_w32_mkdir(const char *, int); +extern int rb_w32_rmdir(const char *); #ifdef __BORLANDC__ extern int rb_w32_fstat(int, struct stat *); -- cgit v1.2.3