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

ruby-changes:23084

From: nobu <ko1@a...>
Date: Mon, 26 Mar 2012 13:51:39 +0900 (JST)
Subject: [ruby-changes:23084] nobu:r35134 (trunk): * win32/win32.c (check_if_dir, check_if_wdir): fix for Visual C++

nobu	2012-03-26 13:51:27 +0900 (Mon, 26 Mar 2012)

  New Revision: 35134

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

  Log:
    * win32/win32.c (check_if_dir, check_if_wdir): fix for Visual C++
      not to use S_ISDIR().  [Feature #2408][ruby-core:26925]
    * ruby.c (load_file_internal): ditto.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35133)
+++ ChangeLog	(revision 35134)
@@ -1,3 +1,10 @@
+Mon Mar 26 13:51:23 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* win32/win32.c (check_if_dir, check_if_wdir): fix for Visual C++
+	  not to use S_ISDIR().  [Feature #2408][ruby-core:26925]
+
+	* ruby.c (load_file_internal): ditto.
+
 Mon Mar 26 11:46:01 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* ruby.c (load_file_internal): bail out if the script is a directory.
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 35133)
+++ win32/win32.c	(revision 35134)
@@ -5188,9 +5188,18 @@
 static int
 check_if_dir(const char *file)
 {
-    struct stati64 st;
-    if (rb_w32_stati64(file, &st) != 0 || !S_ISDIR(st.st_mode))
+    DWORD attr;
+    WCHAR *wfile;
+
+    if (!(wfile = filecp_to_wstr(file, NULL)))
 	return FALSE;
+    attr = GetFileAttributesW(wfile);
+    if (attr == (DWORD)-1L ||
+	!(attr & FILE_ATTRIBUTE_DIRECTORY) ||
+	check_valid_dir(wfile)) {
+	return FALSE;
+    }
+    free(wfile);
     errno = EISDIR;
     return TRUE;
 }
@@ -5199,9 +5208,12 @@
 static int
 check_if_wdir(const WCHAR *wfile)
 {
-    struct stati64 st;
-    if (wstati64(wfile, &st) != 0 || !S_ISDIR(st.st_mode))
+    DWORD attr = GetFileAttributesW(wfile);
+    if (attr == (DWORD)-1L ||
+	!(attr & FILE_ATTRIBUTE_DIRECTORY) ||
+	check_valid_dir(wfile)) {
 	return FALSE;
+    }
     errno = EISDIR;
     return TRUE;
 }
Index: ruby.c
===================================================================
--- ruby.c	(revision 35133)
+++ ruby.c	(revision 35134)
@@ -1524,19 +1524,20 @@
 	}
 #endif
 	if ((fd = rb_cloexec_open(fname, mode, 0)) < 0) {
-	  load_failed:
 	    rb_load_fail(fname_v, strerror(errno));
 	}
         rb_update_max_fd(fd);
+#if !defined DOSISH && !defined __CYGWIN__
 	{
 	    struct stat st;
-	    if (fstat(fd, &st) != 0) goto load_failed;
+	    if (fstat(fd, &st) != 0)
+		rb_load_fail(fname_v, strerror(errno));
 	    if (S_ISDIR(st.st_mode)) {
 		errno = EISDIR;
-		goto load_failed;
+		rb_load_fail(fname_v, strerror(EISDIR));
 	    }
 	}
-
+#endif
 	f = rb_io_fdopen(fd, mode, fname);
     }
 

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

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