| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 140 scoped_ptr<char[]> buf(new char[kBufferSize]); | 140 std::unique_ptr<char[]> buf(new char[kBufferSize]); |
| 141 size_t len; | 141 size_t len; |
| 142 size_t size = 0; | 142 size_t size = 0; |
| 143 bool read_status = true; | 143 bool read_status = true; |
| 144 | 144 |
| 145 // Many files supplied in |path| have incorrect size (proc files etc). | 145 // Many files supplied in |path| have incorrect size (proc files etc). |
| 146 // Hence, the file is read sequentially as opposed to a one-shot read. | 146 // Hence, the file is read sequentially as opposed to a one-shot read. |
| 147 while ((len = fread(buf.get(), 1, kBufferSize, file)) > 0) { | 147 while ((len = fread(buf.get(), 1, kBufferSize, file)) > 0) { |
| 148 if (contents) | 148 if (contents) |
| 149 contents->append(buf.get(), std::min(len, max_size - size)); | 149 contents->append(buf.get(), std::min(len, max_size - size)); |
| 150 | 150 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { | 254 (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) { |
| 255 return count; | 255 return count; |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 return -1; | 259 return -1; |
| 260 } | 260 } |
| 261 #endif // !defined(OS_NACL_NONSFI) | 261 #endif // !defined(OS_NACL_NONSFI) |
| 262 | 262 |
| 263 } // namespace base | 263 } // namespace base |
| OLD | NEW |