| 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_util.h" | 5 #include "base/files/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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 line2.erase(end2 + 1); | 117 line2.erase(end2 + 1); |
| 118 | 118 |
| 119 if (line1 != line2) | 119 if (line1 != line2) |
| 120 return false; | 120 return false; |
| 121 } while (!file1.eof() || !file2.eof()); | 121 } while (!file1.eof() || !file2.eof()); |
| 122 | 122 |
| 123 return true; | 123 return true; |
| 124 } | 124 } |
| 125 #endif // !defined(OS_NACL_NONSFI) | 125 #endif // !defined(OS_NACL_NONSFI) |
| 126 | 126 |
| 127 bool ReadFileToString(const FilePath& path, | 127 bool ReadFileToStringWithMaxSize(const FilePath& path, |
| 128 std::string* contents, | 128 std::string* contents, |
| 129 size_t max_size) { | 129 size_t max_size) { |
| 130 if (contents) | 130 if (contents) |
| 131 contents->clear(); | 131 contents->clear(); |
| 132 if (path.ReferencesParent()) | 132 if (path.ReferencesParent()) |
| 133 return false; | 133 return false; |
| 134 FILE* file = OpenFile(path, "rb"); | 134 FILE* file = OpenFile(path, "rb"); |
| 135 if (!file) { | 135 if (!file) { |
| 136 return false; | 136 return false; |
| 137 } | 137 } |
| 138 | 138 |
| 139 const size_t kBufferSize = 1 << 16; | 139 const size_t kBufferSize = 1 << 16; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 155 | 155 |
| 156 size += len; | 156 size += len; |
| 157 } | 157 } |
| 158 read_status = read_status && !ferror(file); | 158 read_status = read_status && !ferror(file); |
| 159 CloseFile(file); | 159 CloseFile(file); |
| 160 | 160 |
| 161 return read_status; | 161 return read_status; |
| 162 } | 162 } |
| 163 | 163 |
| 164 bool ReadFileToString(const FilePath& path, std::string* contents) { | 164 bool ReadFileToString(const FilePath& path, std::string* contents) { |
| 165 return ReadFileToString(path, contents, std::numeric_limits<size_t>::max()); | 165 return ReadFileToStringWithMaxSize(path, contents, |
| 166 std::numeric_limits<size_t>::max()); |
| 166 } | 167 } |
| 167 | 168 |
| 168 #if !defined(OS_NACL_NONSFI) | 169 #if !defined(OS_NACL_NONSFI) |
| 169 bool IsDirectoryEmpty(const FilePath& dir_path) { | 170 bool IsDirectoryEmpty(const FilePath& dir_path) { |
| 170 FileEnumerator files(dir_path, false, | 171 FileEnumerator files(dir_path, false, |
| 171 FileEnumerator::FILES | FileEnumerator::DIRECTORIES); | 172 FileEnumerator::FILES | FileEnumerator::DIRECTORIES); |
| 172 if (files.Next().empty()) | 173 if (files.Next().empty()) |
| 173 return true; | 174 return true; |
| 174 return false; | 175 return false; |
| 175 } | 176 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { | 254 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { |
| 254 return count; | 255 return count; |
| 255 } | 256 } |
| 256 } | 257 } |
| 257 | 258 |
| 258 return -1; | 259 return -1; |
| 259 } | 260 } |
| 260 #endif // !defined(OS_NACL_NONSFI) | 261 #endif // !defined(OS_NACL_NONSFI) |
| 261 | 262 |
| 262 } // namespace base | 263 } // namespace base |
| OLD | NEW |