summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-13 10:40:06 +0000
committerocean <ocean@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-13 10:40:06 +0000
commitd20bc9f4d2d2bfe435ccf3318cc72ad2c3b82fa8 (patch)
tree03187816221546a103173cf1750f094e00c6e5d4 /win32
parente850d8aced07be7ac2911acc8375e941d1f86b33 (diff)
* win32/win32.c (rb_w32_mkdir): should set EEXIST (not EACCES)
if file or directory already exists. (bcc32) * win32/win32.c (rb_w32_rmdir): should set ENOTDIR (not EINVAL) if it is not directory. (bcc32, win32) * win32/win32.c (rb_w32_rmdir, rb_w32_unlink): restore FILE_ATTRIBUTE_READONLY flag on function failure. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32')
-rw-r--r--win32/win32.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/win32/win32.c b/win32/win32.c
index c5ca269732..ee0c229621 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -157,6 +157,7 @@ static struct {
{ ERROR_NEGATIVE_SEEK, EINVAL },
{ ERROR_SEEK_ON_DEVICE, EACCES },
{ ERROR_DIR_NOT_EMPTY, ENOTEMPTY },
+ { ERROR_DIRECTORY, ENOTDIR },
{ ERROR_NOT_LOCKED, EACCES },
{ ERROR_BAD_PATHNAME, ENOENT },
{ ERROR_MAX_THRDS_REACHED, EAGAIN },
@@ -3394,19 +3395,17 @@ 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)
+ if (CreateDirectory(path, NULL) == FALSE) {
+ errno = map_errno(GetLastError());
break;
+ }
if (chmod(path, mode) == -1) {
- int save_errno = errno;
- rmdir(path);
- errno = save_errno;
+ RemoveDirectory(path);
break;
}
ret = 0;
@@ -3417,37 +3416,38 @@ rb_w32_mkdir(const char *path, int mode)
int
rb_w32_rmdir(const char *path)
{
- DWORD attr;
- int ret;
+ int ret = 0;
RUBY_CRITICAL({
- attr = GetFileAttributes(path);
+ const DWORD attr = GetFileAttributes(path);
if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
- attr &= ~FILE_ATTRIBUTE_READONLY;
- SetFileAttributes(path, attr);
+ SetFileAttributes(path, attr & ~FILE_ATTRIBUTE_READONLY);
}
- ret = rmdir(path);
- if (ret < 0 && attr != (DWORD)-1) {
- SetFileAttributes(path, attr);
+ if (RemoveDirectory(path) == FALSE) {
+ errno = map_errno(GetLastError());
+ ret = -1;
+ if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
+ SetFileAttributes(path, attr);
+ }
}
});
return ret;
}
-#undef unlink
int
rb_w32_unlink(const char *path)
{
- DWORD attr;
- int ret;
+ int ret = 0;
RUBY_CRITICAL({
- attr = GetFileAttributes(path);
+ const DWORD attr = GetFileAttributes(path);
if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
- attr &= ~FILE_ATTRIBUTE_READONLY;
- SetFileAttributes(path, attr);
+ SetFileAttributes(path, attr & ~FILE_ATTRIBUTE_READONLY);
}
- ret = unlink(path);
- if (ret < 0 && attr != (DWORD)-1) {
- SetFileAttributes(path, attr);
+ if (DeleteFile(path) == FALSE) {
+ errno = map_errno(GetLastError());
+ ret = -1;
+ if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY)) {
+ SetFileAttributes(path, attr);
+ }
}
});
return ret;