[前][次][番号順一覧][スレッド一覧]

ruby-changes:23079

From: nobu <ko1@a...>
Date: Mon, 26 Mar 2012 11:41:17 +0900 (JST)
Subject: [ruby-changes:23079] nobu:r35129 (trunk): * win32/win32.c (rb_w32_open, rb_w32_wopen): check if the file is a

nobu	2012-03-26 11:41:04 +0900 (Mon, 26 Mar 2012)

  New Revision: 35129

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=35129

  Log:
    * win32/win32.c (rb_w32_open, rb_w32_wopen): check if the file is a
      directory when access denied, to set errno to EISDIR.

  Modified files:
    trunk/ChangeLog
    trunk/win32/win32.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35128)
+++ ChangeLog	(revision 35129)
@@ -1,3 +1,8 @@
+Mon Mar 26 11:41:01 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* string.c (tr_setup_table): fix multiple non latin argument for
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 35128)
+++ win32/win32.c	(revision 35129)
@@ -5185,6 +5185,28 @@
 }
 
 /* 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 */
 int
 rb_w32_open(const char *file, int oflag, ...)
 {
@@ -5197,8 +5219,11 @@
     pmode = va_arg(arg, int);
     va_end(arg);
 
-    if ((oflag & O_TEXT) || !(oflag & O_BINARY))
-	return _open(file, oflag, pmode);
+    if ((oflag & O_TEXT) || !(oflag & O_BINARY)) {
+	ret = _open(file, oflag, pmode);
+	if (ret == -1 && errno == EACCES) check_if_dir(file);
+	return ret;
+    }
 
     if (!(wfile = filecp_to_wstr(file, NULL)))
 	return -1;
@@ -5224,7 +5249,9 @@
 	va_start(arg, oflag);
 	pmode = va_arg(arg, int);
 	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);
@@ -5340,7 +5367,9 @@
 	h = CreateFileW(file, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sec,
 			create, attr, NULL);
 	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));
 	    fd = -1;
 	    goto quit;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]