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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « base/files/file_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/file.h" 5 #include "base/files/file.h"
6 6
7 #include <io.h> 7 #include <io.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 302 }
303 303
304 File::Error File::Unlock() { 304 File::Error File::Unlock() {
305 DCHECK(IsValid()); 305 DCHECK(IsValid());
306 BOOL result = UnlockFile(file_.Get(), 0, 0, MAXDWORD, MAXDWORD); 306 BOOL result = UnlockFile(file_.Get(), 0, 0, MAXDWORD, MAXDWORD);
307 if (!result) 307 if (!result)
308 return OSErrorToFileError(GetLastError()); 308 return OSErrorToFileError(GetLastError());
309 return FILE_OK; 309 return FILE_OK;
310 } 310 }
311 311
312 File File::Duplicate() {
313 if (!IsValid())
314 return File();
315
316 HANDLE other_handle = nullptr;
317
318 if (!::DuplicateHandle(GetCurrentProcess(), // hSourceProcessHandle
319 GetPlatformFile(),
320 GetCurrentProcess(), // hTargetProcessHandle
321 &other_handle,
322 0, // dwDesiredAccess ignored due to SAME_ACCESS
323 FALSE, // !bInheritHandle
324 DUPLICATE_SAME_ACCESS)) {
325 return File(OSErrorToFileError(GetLastError()));
326 }
327
328 File other(other_handle);
329 if (async())
330 other.async_ = true;
331 return other.Pass();
332 }
333
312 // Static. 334 // Static.
313 File::Error File::OSErrorToFileError(DWORD last_error) { 335 File::Error File::OSErrorToFileError(DWORD last_error) {
314 switch (last_error) { 336 switch (last_error) {
315 case ERROR_SHARING_VIOLATION: 337 case ERROR_SHARING_VIOLATION:
316 return FILE_ERROR_IN_USE; 338 return FILE_ERROR_IN_USE;
317 case ERROR_FILE_EXISTS: 339 case ERROR_FILE_EXISTS:
318 return FILE_ERROR_EXISTS; 340 return FILE_ERROR_EXISTS;
319 case ERROR_FILE_NOT_FOUND: 341 case ERROR_FILE_NOT_FOUND:
320 case ERROR_PATH_NOT_FOUND: 342 case ERROR_PATH_NOT_FOUND:
321 return FILE_ERROR_NOT_FOUND; 343 return FILE_ERROR_NOT_FOUND;
(...skipping 22 matching lines...) Expand all
344 last_error); 366 last_error);
345 return FILE_ERROR_FAILED; 367 return FILE_ERROR_FAILED;
346 } 368 }
347 } 369 }
348 370
349 void File::SetPlatformFile(PlatformFile file) { 371 void File::SetPlatformFile(PlatformFile file) {
350 file_.Set(file); 372 file_.Set(file);
351 } 373 }
352 374
353 } // namespace base 375 } // namespace base
OLDNEW
« 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