Skip to content

Commit

Permalink
* io.c (dir_s_mkdir): win32 special processing doesn't need any longer.
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
unak committed Dec 7, 2004
1 parent 69b64a7 commit 571e136
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
Tue Dec 7 13:42:07 2004 NAKAMURA Usaku <[email protected]>

* 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.

Tue Dec 7 00:27:37 2004 Yukihiro Matsumoto <[email protected]>

* process.c (proc_setgroups): [ruby-dev:25081]
Expand Down
5 changes: 0 additions & 5 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,13 +895,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);
}
Expand Down
39 changes: 39 additions & 0 deletions win32/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down
7 changes: 7 additions & 0 deletions win32/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 *);
Expand Down

0 comments on commit 571e136

Please sign in to comment.