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

ruby-changes:37970

From: nobu <ko1@a...>
Date: Sun, 22 Mar 2015 11:26:41 +0900 (JST)
Subject: [ruby-changes:37970] nobu:r50051 (trunk): win32.c: stat_by_find

nobu	2015-03-22 11:26:28 +0900 (Sun, 22 Mar 2015)

  New Revision: 50051

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

  Log:
    win32.c: stat_by_find
    
    * win32/win32.c (stat_by_find): extract from winnt_stat.

  Modified files:
    trunk/win32/Makefile.sub
    trunk/win32/win32.c
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 50050)
+++ win32/win32.c	(revision 50051)
@@ -56,6 +56,10 @@ https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L56
 # define CharNextExA(cp, p, flags) CharNextExA((WORD)(cp), (p), (flags))
 #endif
 
+#if _WIN32_WINNT < 0x0600
+DWORD WINAPI GetFinalPathNameByHandleW(HANDLE, LPWSTR, DWORD, DWORD);
+#endif
+
 static int w32_stati64(const char *path, struct stati64 *st, UINT cp);
 static char *w32_getenv(const char *name, UINT cp);
 
@@ -5038,10 +5042,39 @@ check_valid_dir(const WCHAR *path) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5042
 
 /* License: Ruby's */
 static int
-winnt_stat(const WCHAR *path, struct stati64 *st)
+stat_by_find(const WCHAR *path, struct stati64 *st)
 {
     HANDLE h;
     WIN32_FIND_DATAW wfd;
+    /* GetFileAttributesEx failed; check why. */
+    int e = GetLastError();
+
+    if ((e == ERROR_FILE_NOT_FOUND) || (e == ERROR_INVALID_NAME)
+	|| (e == ERROR_PATH_NOT_FOUND || (e == ERROR_BAD_NETPATH))) {
+	errno = map_errno(e);
+	return -1;
+    }
+
+    /* Fall back to FindFirstFile for ERROR_SHARING_VIOLATION */
+    h = FindFirstFileW(path, &wfd);
+    if (h == INVALID_HANDLE_VALUE) {
+	errno = map_errno(GetLastError());
+	return -1;
+    }
+    FindClose(h);
+    st->st_mode  = fileattr_to_unixmode(wfd.dwFileAttributes, path);
+    st->st_atime = filetime_to_unixtime(&wfd.ftLastAccessTime);
+    st->st_mtime = filetime_to_unixtime(&wfd.ftLastWriteTime);
+    st->st_ctime = filetime_to_unixtime(&wfd.ftCreationTime);
+    st->st_size = ((__int64)wfd.nFileSizeHigh << 32) | wfd.nFileSizeLow;
+    st->st_nlink = 1;
+    return 0;
+}
+
+/* License: Ruby's */
+static int
+winnt_stat(const WCHAR *path, struct stati64 *st)
+{
     WIN32_FILE_ATTRIBUTE_DATA wfa;
     const WCHAR *p = path;
 
@@ -5067,29 +5100,7 @@ winnt_stat(const WCHAR *path, struct sta https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5100
 	st->st_ctime = filetime_to_unixtime(&wfa.ftCreationTime);
     }
     else {
-	/* GetFileAttributesEx failed; check why. */
-	int e = GetLastError();
-
-	if ((e == ERROR_FILE_NOT_FOUND) || (e == ERROR_INVALID_NAME)
-	    || (e == ERROR_PATH_NOT_FOUND || (e == ERROR_BAD_NETPATH))) {
-	    errno = map_errno(e);
-	    return -1;
-	}
-
-	/* Fall back to FindFirstFile for ERROR_SHARING_VIOLATION */
-	h = FindFirstFileW(path, &wfd);
-	if (h != INVALID_HANDLE_VALUE) {
-	    FindClose(h);
-	    st->st_mode  = fileattr_to_unixmode(wfd.dwFileAttributes, path);
-	    st->st_atime = filetime_to_unixtime(&wfd.ftLastAccessTime);
-	    st->st_mtime = filetime_to_unixtime(&wfd.ftLastWriteTime);
-	    st->st_ctime = filetime_to_unixtime(&wfd.ftCreationTime);
-	    st->st_size = ((__int64)wfd.nFileSizeHigh << 32) | wfd.nFileSizeLow;
-	}
-	else {
-	    errno = map_errno(GetLastError());
-	    return -1;
-	}
+	if (stat_by_find(path, st)) return -1;
     }
 
     st->st_dev = st->st_rdev = (iswalpha(path[0]) && path[1] == L':') ?
Index: win32/Makefile.sub
===================================================================
--- win32/Makefile.sub	(revision 50050)
+++ win32/Makefile.sub	(revision 50051)
@@ -122,6 +122,9 @@ PLATFORM = mswin32 https://github.com/ruby/ruby/blob/trunk/win32/Makefile.sub#L122
 !if !defined(RT)
 !error RT not defined.  Retry from configure pass.
 !endif
+!ifndef NTVER
+NTVER = 0x0600
+!endif
 !ifdef NTVER
 ARCHDEFS = -D_WIN32_WINNT=$(NTVER) $(ARCHDEFS)
 !endif

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

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