OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |