Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: base/files/file_util.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/files/file_util.h ('k') | base/files/file_util_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « base/files/file_util.h ('k') | base/files/file_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698