Skip to content

Commit 571e136

Browse files
committed
* 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
1 parent 69b64a7 commit 571e136

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

ChangeLog

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Tue Dec 7 13:42:07 2004 NAKAMURA Usaku <usa@ruby-lang.org>
2+
3+
* io.c (dir_s_mkdir): win32 special processing doesn't need any longer.
4+
5+
* win32/win32.[ch] (rb_w32_mkdir): new function. POSIX.1 compatible
6+
interface.
7+
8+
* win32/win32.[ch] (rb_w32_rmdir): new function.
9+
110
Tue Dec 7 00:27:37 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
211

312
* process.c (proc_setgroups): [ruby-dev:25081]

dir.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -895,13 +895,8 @@ dir_s_mkdir(argc, argv, obj)
895895
}
896896

897897
check_dirname(&path);
898-
#ifndef _WIN32
899898
if (mkdir(RSTRING(path)->ptr, mode) == -1)
900899
rb_sys_fail(RSTRING(path)->ptr);
901-
#else
902-
if (mkdir(RSTRING(path)->ptr) == -1)
903-
rb_sys_fail(RSTRING(path)->ptr);
904-
#endif
905900

906901
return INT2FIX(0);
907902
}

win32/win32.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3430,6 +3430,45 @@ rb_w32_isatty(int fd)
34303430
return 1;
34313431
}
34323432

3433+
#undef mkdir
3434+
#undef rmdir
3435+
int
3436+
rb_w32_mkdir(const char *path, int mode)
3437+
{
3438+
int ret = -1;
3439+
RUBY_CRITICAL(do {
3440+
if (mkdir(path) == -1)
3441+
break;
3442+
if (chmod(path, mode) == -1) {
3443+
int save_errno = errno;
3444+
rmdir(path);
3445+
errno = save_errno;
3446+
break;
3447+
}
3448+
ret = 0;
3449+
} while (0));
3450+
return ret;
3451+
}
3452+
3453+
int
3454+
rb_w32_rmdir(const char *path)
3455+
{
3456+
DWORD attr;
3457+
int ret;
3458+
RUBY_CRITICAL({
3459+
attr = GetFileAttributes(path);
3460+
if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
3461+
attr &= ~FILE_ATTRIBUTE_READONLY;
3462+
SetFileAttributes(path, attr);
3463+
}
3464+
ret = rmdir(path);
3465+
if (ret < 0 && attr != (DWORD)-1) {
3466+
SetFileAttributes(path, attr);
3467+
}
3468+
});
3469+
return ret;
3470+
}
3471+
34333472
//
34343473
// Fix bcc32's stdio bug
34353474
//

win32/win32.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ extern "C++" {
130130
#undef isatty
131131
#define isatty(h) rb_w32_isatty(h)
132132

133+
#undef mkdir
134+
#define mkdir(p, m) rb_w32_mkdir(p, m)
135+
#undef rmdir
136+
#define rmdir(p) rb_w32_rmdir(p)
137+
133138
#ifdef __MINGW32__
134139
struct timezone {
135140
int tz_minuteswest;
@@ -190,6 +195,8 @@ extern int kill(int, int);
190195
extern int fcntl(int, int, ...);
191196
extern pid_t rb_w32_getpid(void);
192197
extern int rb_w32_isatty(int);
198+
extern int rb_w32_mkdir(const char *, int);
199+
extern int rb_w32_rmdir(const char *);
193200

194201
#ifdef __BORLANDC__
195202
extern int rb_w32_fstat(int, struct stat *);

0 commit comments

Comments
 (0)