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 <propvarutil.h> | 8 #include <propvarutil.h> |
9 #include <psapi.h> | 9 #include <psapi.h> |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 DLOG(WARNING) << "writing file " << filename.value() | 715 DLOG(WARNING) << "writing file " << filename.value() |
716 << " failed, error code=" << GetLastError(); | 716 << " failed, error code=" << GetLastError(); |
717 } else { | 717 } else { |
718 // Didn't write all the bytes. | 718 // Didn't write all the bytes. |
719 DLOG(WARNING) << "wrote" << written << " bytes to " | 719 DLOG(WARNING) << "wrote" << written << " bytes to " |
720 << filename.value() << " expected " << size; | 720 << filename.value() << " expected " << size; |
721 } | 721 } |
722 return -1; | 722 return -1; |
723 } | 723 } |
724 | 724 |
| 725 int AppendToFile(const FilePath& filename, const char* data, int size) { |
| 726 base::ThreadRestrictions::AssertIOAllowed(); |
| 727 base::win::ScopedHandle file(CreateFile(filename.value().c_str(), |
| 728 FILE_APPEND_DATA, |
| 729 0, |
| 730 NULL, |
| 731 OPEN_EXISTING, |
| 732 0, |
| 733 NULL)); |
| 734 if (!file) { |
| 735 DLOG(WARNING) << "CreateFile failed for path " << filename.value() |
| 736 << " error code=" << GetLastError(); |
| 737 return -1; |
| 738 } |
| 739 |
| 740 DWORD written; |
| 741 BOOL result = ::WriteFile(file, data, size, &written, NULL); |
| 742 if (result && static_cast<int>(written) == size) |
| 743 return written; |
| 744 |
| 745 if (!result) { |
| 746 // WriteFile failed. |
| 747 DLOG(WARNING) << "writing file " << filename.value() |
| 748 << " failed, error code=" << GetLastError(); |
| 749 } else { |
| 750 // Didn't write all the bytes. |
| 751 DLOG(WARNING) << "wrote" << written << " bytes to " |
| 752 << filename.value() << " expected " << size; |
| 753 } |
| 754 return -1; |
| 755 } |
| 756 |
725 // Gets the current working directory for the process. | 757 // Gets the current working directory for the process. |
726 bool GetCurrentDirectory(FilePath* dir) { | 758 bool GetCurrentDirectory(FilePath* dir) { |
727 base::ThreadRestrictions::AssertIOAllowed(); | 759 base::ThreadRestrictions::AssertIOAllowed(); |
728 | 760 |
729 wchar_t system_buffer[MAX_PATH]; | 761 wchar_t system_buffer[MAX_PATH]; |
730 system_buffer[0] = 0; | 762 system_buffer[0] = 0; |
731 DWORD len = ::GetCurrentDirectory(MAX_PATH, system_buffer); | 763 DWORD len = ::GetCurrentDirectory(MAX_PATH, system_buffer); |
732 if (len == 0 || len > MAX_PATH) | 764 if (len == 0 || len > MAX_PATH) |
733 return false; | 765 return false; |
734 // TODO(evanm): the old behavior of this function was to always strip the | 766 // TODO(evanm): the old behavior of this function was to always strip the |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 HANDLE cp = GetCurrentProcess(); | 1106 HANDLE cp = GetCurrentProcess(); |
1075 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { | 1107 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { |
1076 *nt_path = FilePath(mapped_file_path); | 1108 *nt_path = FilePath(mapped_file_path); |
1077 success = true; | 1109 success = true; |
1078 } | 1110 } |
1079 ::UnmapViewOfFile(file_view); | 1111 ::UnmapViewOfFile(file_view); |
1080 return success; | 1112 return success; |
1081 } | 1113 } |
1082 | 1114 |
1083 } // namespace file_util | 1115 } // namespace file_util |
OLD | NEW |