Index: base/files/file_win.cc |
diff --git a/base/files/file_win.cc b/base/files/file_win.cc |
index 727b5ce1dbbe6e5e7be6e22cef8f1d450515b002..2eb3fad5ae445819466297642620bb5c365a8203 100644 |
--- a/base/files/file_win.cc |
+++ b/base/files/file_win.cc |
@@ -309,6 +309,29 @@ File::Error File::Unlock() { |
return FILE_OK; |
} |
+File File::Duplicate() { |
+ if (!IsValid()) |
+ return File(); |
+ |
+ HANDLE other_handle = nullptr; |
+ |
+ if (!::DuplicateHandle(GetCurrentProcess(), // hSourceProcessHandle |
+ GetPlatformFile(), |
+ GetCurrentProcess(), // hTargetProcessHandle |
+ &other_handle, |
+ 0, // dwDesiredAccess ignored due to SAME_ACCESS |
+ FALSE, // !bInheritHandle |
+ DUPLICATE_SAME_ACCESS)) { |
+ DWORD last_error = GetLastError(); |
+ return File(OSErrorToFileError(last_error)); |
rvargas (doing something else)
2015/03/18 20:56:42
nit: inline last_error
grt (UTC plus 2)
2015/03/19 03:31:03
Done.
|
+ } |
+ |
+ File other(other_handle); |
+ if (async()) |
+ other.async_ = true; |
+ return other.Pass(); |
+} |
+ |
// Static. |
File::Error File::OSErrorToFileError(DWORD last_error) { |
switch (last_error) { |