* win32/win32.c (rb_w32_open, rb_w32_wopen): check if the file is a

directory when access denied, to set errno to EISDIR.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35129 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-03-26 02:41:04 +00:00
parent 73a184cc3a
commit b83ad31c43
2 changed files with 38 additions and 4 deletions

View File

@ -1,3 +1,8 @@
Mon Mar 26 11:41:01 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* win32/win32.c (rb_w32_open, rb_w32_wopen): check if the file is a
directory when access denied, to set errno to EISDIR.
Sun Mar 25 18:13:14 2012 NARUSE, Yui <naruse@ruby-lang.org> Sun Mar 25 18:13:14 2012 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (tr_setup_table): fix multiple non latin argument for * string.c (tr_setup_table): fix multiple non latin argument for

View File

@ -5184,6 +5184,28 @@ rb_w32_uopen(const char *file, int oflag, ...)
return ret; return ret;
} }
/* License: Ruby's */
static int
check_if_dir(const char *file)
{
struct stati64 st;
if (rb_w32_stati64(file, &st) != 0 || !S_ISDIR(st.st_mode))
return FALSE;
errno = EISDIR;
return TRUE;
}
/* License: Ruby's */
static int
check_if_wdir(const WCHAR *wfile)
{
struct stati64 st;
if (wstati64(wfile, &st) != 0 || !S_ISDIR(st.st_mode))
return FALSE;
errno = EISDIR;
return TRUE;
}
/* License: Ruby's */ /* License: Ruby's */
int int
rb_w32_open(const char *file, int oflag, ...) rb_w32_open(const char *file, int oflag, ...)
@ -5197,8 +5219,11 @@ rb_w32_open(const char *file, int oflag, ...)
pmode = va_arg(arg, int); pmode = va_arg(arg, int);
va_end(arg); va_end(arg);
if ((oflag & O_TEXT) || !(oflag & O_BINARY)) if ((oflag & O_TEXT) || !(oflag & O_BINARY)) {
return _open(file, oflag, pmode); ret = _open(file, oflag, pmode);
if (ret == -1 && errno == EACCES) check_if_dir(file);
return ret;
}
if (!(wfile = filecp_to_wstr(file, NULL))) if (!(wfile = filecp_to_wstr(file, NULL)))
return -1; return -1;
@ -5224,7 +5249,9 @@ rb_w32_wopen(const WCHAR *file, int oflag, ...)
va_start(arg, oflag); va_start(arg, oflag);
pmode = va_arg(arg, int); pmode = va_arg(arg, int);
va_end(arg); va_end(arg);
return _wopen(file, oflag, pmode); fd = _wopen(file, oflag, pmode);
if (fd == -1 && errno == EACCES) check_if_wdir(file);
return fd;
} }
sec.nLength = sizeof(sec); sec.nLength = sizeof(sec);
@ -5340,7 +5367,9 @@ rb_w32_wopen(const WCHAR *file, int oflag, ...)
h = CreateFileW(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sec, h = CreateFileW(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sec,
create, attr, NULL); create, attr, NULL);
if (h == INVALID_HANDLE_VALUE) { if (h == INVALID_HANDLE_VALUE) {
errno = map_errno(GetLastError()); DWORD e = GetLastError();
if (e != ERROR_ACCESS_DENIED || !check_if_wdir(file))
errno = map_errno(e);
MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock)); MTHREAD_ONLY(LeaveCriticalSection(&_pioinfo(fd)->lock));
fd = -1; fd = -1;
goto quit; goto quit;