Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(937)

Unified Diff: base/files/file_win.cc

Issue 1017243002: Add File::Duplicate to duplicate a file handle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: posix fix Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/files/file_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_win.cc
diff --git a/base/files/file_win.cc b/base/files/file_win.cc
index 727b5ce1dbbe6e5e7be6e22cef8f1d450515b002..9f3033c845bb5a8e1469765c9b01c9b330167c7e 100644
--- a/base/files/file_win.cc
+++ b/base/files/file_win.cc
@@ -309,6 +309,28 @@ 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)) {
+ return File(OSErrorToFileError(GetLastError()));
+ }
+
+ File other(other_handle);
+ if (async())
+ other.async_ = true;
+ return other.Pass();
+}
+
// Static.
File::Error File::OSErrorToFileError(DWORD last_error) {
switch (last_error) {
« no previous file with comments | « base/files/file_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698