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 DWORD last_error = GetLastError(); | |
326 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.
| |
327 } | |
328 | |
329 File other(other_handle); | |
330 if (async()) | |
331 other.async_ = true; | |
332 return other.Pass(); | |
333 } | |
334 | |
312 // Static. | 335 // Static. |
313 File::Error File::OSErrorToFileError(DWORD last_error) { | 336 File::Error File::OSErrorToFileError(DWORD last_error) { |
314 switch (last_error) { | 337 switch (last_error) { |
315 case ERROR_SHARING_VIOLATION: | 338 case ERROR_SHARING_VIOLATION: |
316 return FILE_ERROR_IN_USE; | 339 return FILE_ERROR_IN_USE; |
317 case ERROR_FILE_EXISTS: | 340 case ERROR_FILE_EXISTS: |
318 return FILE_ERROR_EXISTS; | 341 return FILE_ERROR_EXISTS; |
319 case ERROR_FILE_NOT_FOUND: | 342 case ERROR_FILE_NOT_FOUND: |
320 case ERROR_PATH_NOT_FOUND: | 343 case ERROR_PATH_NOT_FOUND: |
321 return FILE_ERROR_NOT_FOUND; | 344 return FILE_ERROR_NOT_FOUND; |
(...skipping 22 matching lines...) Expand all Loading... | |
344 last_error); | 367 last_error); |
345 return FILE_ERROR_FAILED; | 368 return FILE_ERROR_FAILED; |
346 } | 369 } |
347 } | 370 } |
348 | 371 |
349 void File::SetPlatformFile(PlatformFile file) { | 372 void File::SetPlatformFile(PlatformFile file) { |
350 file_.Set(file); | 373 file_.Set(file); |
351 } | 374 } |
352 | 375 |
353 } // namespace base | 376 } // namespace base |
OLD | NEW |