| 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 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <io.h> | 8 #include <io.h> |
| 9 #endif | 9 #endif |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 else if (end2 + 1 < line2.length()) | 123 else if (end2 + 1 < line2.length()) |
| 124 line2.erase(end2 + 1); | 124 line2.erase(end2 + 1); |
| 125 | 125 |
| 126 if (line1 != line2) | 126 if (line1 != line2) |
| 127 return false; | 127 return false; |
| 128 } while (!file1.eof() || !file2.eof()); | 128 } while (!file1.eof() || !file2.eof()); |
| 129 | 129 |
| 130 return true; | 130 return true; |
| 131 } | 131 } |
| 132 | 132 |
| 133 } // namespace base | |
| 134 | |
| 135 // ----------------------------------------------------------------------------- | |
| 136 | |
| 137 namespace file_util { | |
| 138 | |
| 139 using base::FileEnumerator; | |
| 140 using base::FilePath; | |
| 141 using base::kExtensionSeparator; | |
| 142 using base::kMaxUniqueFiles; | |
| 143 | |
| 144 bool ReadFileToString(const FilePath& path, std::string* contents) { | 133 bool ReadFileToString(const FilePath& path, std::string* contents) { |
| 145 if (path.ReferencesParent()) | 134 if (path.ReferencesParent()) |
| 146 return false; | 135 return false; |
| 147 FILE* file = OpenFile(path, "rb"); | 136 FILE* file = file_util::OpenFile(path, "rb"); |
| 148 if (!file) { | 137 if (!file) { |
| 149 return false; | 138 return false; |
| 150 } | 139 } |
| 151 | 140 |
| 152 char buf[1 << 16]; | 141 char buf[1 << 16]; |
| 153 size_t len; | 142 size_t len; |
| 154 while ((len = fread(buf, 1, sizeof(buf), file)) > 0) { | 143 while ((len = fread(buf, 1, sizeof(buf), file)) > 0) { |
| 155 if (contents) | 144 if (contents) |
| 156 contents->append(buf, len); | 145 contents->append(buf, len); |
| 157 } | 146 } |
| 158 CloseFile(file); | 147 file_util::CloseFile(file); |
| 159 | 148 |
| 160 return true; | 149 return true; |
| 161 } | 150 } |
| 162 | 151 |
| 152 } // namespace base |
| 153 |
| 154 // ----------------------------------------------------------------------------- |
| 155 |
| 156 namespace file_util { |
| 157 |
| 158 using base::FileEnumerator; |
| 159 using base::FilePath; |
| 160 using base::kExtensionSeparator; |
| 161 using base::kMaxUniqueFiles; |
| 162 |
| 163 bool IsDirectoryEmpty(const FilePath& dir_path) { | 163 bool IsDirectoryEmpty(const FilePath& dir_path) { |
| 164 FileEnumerator files(dir_path, false, | 164 FileEnumerator files(dir_path, false, |
| 165 FileEnumerator::FILES | FileEnumerator::DIRECTORIES); | 165 FileEnumerator::FILES | FileEnumerator::DIRECTORIES); |
| 166 if (files.Next().empty()) | 166 if (files.Next().empty()) |
| 167 return true; | 167 return true; |
| 168 return false; | 168 return false; |
| 169 } | 169 } |
| 170 | 170 |
| 171 FILE* CreateAndOpenTemporaryFile(FilePath* path) { | 171 FILE* CreateAndOpenTemporaryFile(FilePath* path) { |
| 172 FilePath directory; | 172 FilePath directory; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (!PathExists(new_path) && | 255 if (!PathExists(new_path) && |
| 256 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { | 256 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { |
| 257 return count; | 257 return count; |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 return -1; | 261 return -1; |
| 262 } | 262 } |
| 263 | 263 |
| 264 } // namespace file_util | 264 } // namespace file_util |
| OLD | NEW |