| 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 <psapi.h> | 8 #include <psapi.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 | 564 |
| 565 return true; | 565 return true; |
| 566 } | 566 } |
| 567 | 567 |
| 568 FILE* OpenFile(const FilePath& filename, const char* mode) { | 568 FILE* OpenFile(const FilePath& filename, const char* mode) { |
| 569 ThreadRestrictions::AssertIOAllowed(); | 569 ThreadRestrictions::AssertIOAllowed(); |
| 570 std::wstring w_mode = ASCIIToWide(std::string(mode)); | 570 std::wstring w_mode = ASCIIToWide(std::string(mode)); |
| 571 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); | 571 return _wfsopen(filename.value().c_str(), w_mode.c_str(), _SH_DENYNO); |
| 572 } | 572 } |
| 573 | 573 |
| 574 int ReadFile(const FilePath& filename, char* data, int size) { | 574 int ReadFile(const FilePath& filename, char* data, int max_size) { |
| 575 ThreadRestrictions::AssertIOAllowed(); | 575 ThreadRestrictions::AssertIOAllowed(); |
| 576 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), | 576 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), |
| 577 GENERIC_READ, | 577 GENERIC_READ, |
| 578 FILE_SHARE_READ | FILE_SHARE_WRITE, | 578 FILE_SHARE_READ | FILE_SHARE_WRITE, |
| 579 NULL, | 579 NULL, |
| 580 OPEN_EXISTING, | 580 OPEN_EXISTING, |
| 581 FILE_FLAG_SEQUENTIAL_SCAN, | 581 FILE_FLAG_SEQUENTIAL_SCAN, |
| 582 NULL)); | 582 NULL)); |
| 583 if (!file) | 583 if (!file) |
| 584 return -1; | 584 return -1; |
| 585 | 585 |
| 586 DWORD read; | 586 DWORD read; |
| 587 if (::ReadFile(file, data, size, &read, NULL) && | 587 if (::ReadFile(file, data, max_size, &read, NULL)) |
| 588 static_cast<int>(read) == size) | |
| 589 return read; | 588 return read; |
| 589 |
| 590 return -1; | 590 return -1; |
| 591 } | 591 } |
| 592 | 592 |
| 593 int WriteFile(const FilePath& filename, const char* data, int size) { | 593 int WriteFile(const FilePath& filename, const char* data, int size) { |
| 594 ThreadRestrictions::AssertIOAllowed(); | 594 ThreadRestrictions::AssertIOAllowed(); |
| 595 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), | 595 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), |
| 596 GENERIC_WRITE, | 596 GENERIC_WRITE, |
| 597 0, | 597 0, |
| 598 NULL, | 598 NULL, |
| 599 CREATE_ALWAYS, | 599 CREATE_ALWAYS, |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 // Like Move, this function is not transactional, so we just | 780 // Like Move, this function is not transactional, so we just |
| 781 // leave the copied bits behind if deleting from_path fails. | 781 // leave the copied bits behind if deleting from_path fails. |
| 782 // If to_path exists previously then we have already overwritten | 782 // If to_path exists previously then we have already overwritten |
| 783 // it by now, we don't get better off by deleting the new bits. | 783 // it by now, we don't get better off by deleting the new bits. |
| 784 } | 784 } |
| 785 return false; | 785 return false; |
| 786 } | 786 } |
| 787 | 787 |
| 788 } // namespace internal | 788 } // namespace internal |
| 789 } // namespace base | 789 } // namespace base |
| OLD | NEW |