| 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/file_util.h" | 5 #include "base/file_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <io.h> |
| 8 #include <psapi.h> | 9 #include <psapi.h> |
| 9 #include <shellapi.h> | 10 #include <shellapi.h> |
| 10 #include <shlobj.h> | 11 #include <shlobj.h> |
| 11 #include <time.h> | 12 #include <time.h> |
| 12 | 13 |
| 13 #include <algorithm> | 14 #include <algorithm> |
| 14 #include <limits> | 15 #include <limits> |
| 15 #include <string> | 16 #include <string> |
| 16 | 17 |
| 17 #include "base/files/file_enumerator.h" | 18 #include "base/files/file_enumerator.h" |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 | 572 |
| 572 return true; | 573 return true; |
| 573 } | 574 } |
| 574 | 575 |
| 575 FILE* OpenFile(const FilePath& filename, const char* mode) { | 576 FILE* OpenFile(const FilePath& filename, const char* mode) { |
| 576 ThreadRestrictions::AssertIOAllowed(); | 577 ThreadRestrictions::AssertIOAllowed(); |
| 577 std::wstring w_mode = ASCIIToWide(std::string(mode)); | 578 std::wstring w_mode = ASCIIToWide(std::string(mode)); |
| 578 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); | 579 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); |
| 579 } | 580 } |
| 580 | 581 |
| 582 FILE* FileToFILE(File file, const char* mode) { |
| 583 if (!file.IsValid()) |
| 584 return NULL; |
| 585 int fd = |
| 586 _open_osfhandle(reinterpret_cast<intptr_t>(file.GetPlatformFile()), 0); |
| 587 if (fd < 0) |
| 588 return NULL; |
| 589 file.TakePlatformFile(); |
| 590 FILE* stream = _fdopen(fd, mode); |
| 591 if (!stream) |
| 592 _close(fd); |
| 593 return stream; |
| 594 } |
| 595 |
| 581 int ReadFile(const FilePath& filename, char* data, int max_size) { | 596 int ReadFile(const FilePath& filename, char* data, int max_size) { |
| 582 ThreadRestrictions::AssertIOAllowed(); | 597 ThreadRestrictions::AssertIOAllowed(); |
| 583 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), | 598 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), |
| 584 GENERIC_READ, | 599 GENERIC_READ, |
| 585 FILE_SHARE_READ | FILE_SHARE_WRITE, | 600 FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 586 NULL, | 601 NULL, |
| 587 OPEN_EXISTING, | 602 OPEN_EXISTING, |
| 588 FILE_FLAG_SEQUENTIAL_SCAN, | 603 FILE_FLAG_SEQUENTIAL_SCAN, |
| 589 NULL)); | 604 NULL)); |
| 590 if (!file) | 605 if (!file) |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 // Like Move, this function is not transactional, so we just | 801 // Like Move, this function is not transactional, so we just |
| 787 // leave the copied bits behind if deleting from_path fails. | 802 // leave the copied bits behind if deleting from_path fails. |
| 788 // If to_path exists previously then we have already overwritten | 803 // If to_path exists previously then we have already overwritten |
| 789 // it by now, we don't get better off by deleting the new bits. | 804 // it by now, we don't get better off by deleting the new bits. |
| 790 } | 805 } |
| 791 return false; | 806 return false; |
| 792 } | 807 } |
| 793 | 808 |
| 794 } // namespace internal | 809 } // namespace internal |
| 795 } // namespace base | 810 } // namespace base |
| OLD | NEW |