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

ruby-changes:39621

From: nobu <ko1@a...>
Date: Thu, 27 Aug 2015 12:58:12 +0900 (JST)
Subject: [ruby-changes:39621] nobu:r51702 (trunk): win32.c: open_special

nobu	2015-08-27 12:57:56 +0900 (Thu, 27 Aug 2015)

  New Revision: 51702

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

  Log:
    win32.c: open_special
    
    * win32/win32.c (open_special): extract to open existing file with
      backup semantics.

  Modified files:
    trunk/win32/win32.c
Index: win32/win32.c
===================================================================
--- win32/win32.c	(revision 51701)
+++ win32/win32.c	(revision 51702)
@@ -1837,6 +1837,17 @@ get_final_path(HANDLE f, WCHAR *buf, DWO https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1837
     return func(f, buf, len, flag);
 }
 
+/* License: Ruby's */
+/* TODO: better name */
+static HANDLE
+open_special(const WCHAR *path, DWORD access, DWORD flags)
+{
+    const DWORD share_mode =
+	FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
+    return CreateFileW(path, access, share_mode, NULL, OPEN_EXISTING,
+		       FILE_FLAG_BACKUP_SEMANTICS|flags, NULL);
+}
+
 //
 // The idea here is to read all the directory names into a string table
 // (separated by nulls) and when one of the other dir functions is called
@@ -1867,8 +1878,7 @@ open_dir_handle(const WCHAR *filename, W https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L1878
     // Create the search pattern
     //
 
-    fh = CreateFileW(filename, 0, 0, NULL, OPEN_EXISTING,
-		     FILE_FLAG_BACKUP_SEMANTICS, NULL);
+    fh = open_special(filename, 0, 0);
     if (fh != INVALID_HANDLE_VALUE) {
 	len = get_final_path(fh, fullname, numberof(fullname), 0);
 	CloseHandle(fh);
@@ -4730,10 +4740,7 @@ reparse_symlink(const WCHAR *path, rb_w3 https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4740
 	return ENOSYS;
     }
 
-    f = CreateFileW(path, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
-		    NULL, OPEN_EXISTING,
-		    FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_OPEN_REPARSE_POINT,
-		    NULL);
+    f = open_special(path, 0, FILE_FLAG_OPEN_REPARSE_POINT);
     if (f == INVALID_HANDLE_VALUE) {
 	return GetLastError();
     }
@@ -4974,11 +4981,8 @@ rb_w32_getenv(const char *name) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L4981
 static DWORD
 get_volume_serial_number(const WCHAR *path)
 {
-    const DWORD share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
-    const DWORD creation = OPEN_EXISTING;
-    const DWORD flags = FILE_FLAG_BACKUP_SEMANTICS;
     BY_HANDLE_FILE_INFORMATION st = {0};
-    HANDLE h = CreateFileW(path, 0, share_mode, NULL, creation, flags, NULL);
+    HANDLE h = open_special(path, 0, 0);
     BOOL ret;
 
     if (h == INVALID_HANDLE_VALUE) return 0;
@@ -5011,10 +5015,9 @@ wrename(const WCHAR *oldpath, const WCHA https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5015
 	return -1;
     }
     if (oldatts & FILE_ATTRIBUTE_REPARSE_POINT) {
-	HANDLE fh = CreateFileW(oldpath, 0, 0, NULL, OPEN_EXISTING,
-				FILE_FLAG_BACKUP_SEMANTICS, NULL);
+	HANDLE fh = open_special(oldpath, 0, 0);
 	if (fh == INVALID_HANDLE_VALUE) {
-	    int e = GetLastError();
+	    DWORD e = GetLastError();
 	    if (e == ERROR_CANT_RESOLVE_FILENAME) {
 		errno = ELOOP;
 		return -1;
@@ -5367,8 +5370,7 @@ winnt_stat(const WCHAR *path, struct sta https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L5370
     HANDLE f;
 
     memset(st, 0, sizeof(*st));
-    f = CreateFileW(path, 0, 0, NULL, OPEN_EXISTING,
-		    FILE_FLAG_BACKUP_SEMANTICS, NULL);
+    f = open_special(path, 0, 0);
     if (f != INVALID_HANDLE_VALUE) {
 	WCHAR finalname[MAX_PATH];
 	const DWORD attr = stati64_handle(f, st);
@@ -7084,8 +7086,7 @@ wutime(const WCHAR *path, const struct u https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L7086
 	const DWORD attr = GetFileAttributesW(path);
 	if (attr != (DWORD)-1 && (attr & FILE_ATTRIBUTE_READONLY))
 	    SetFileAttributesW(path, attr & ~FILE_ATTRIBUTE_READONLY);
-	hFile = CreateFileW(path, GENERIC_WRITE, 0, 0, OPEN_EXISTING,
-			    FILE_FLAG_BACKUP_SEMANTICS, 0);
+	hFile = open_special(path, GENERIC_WRITE, 0);
 	if (hFile == INVALID_HANDLE_VALUE) {
 	    errno = map_errno(GetLastError());
 	    ret = -1;

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

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