[go: nahoru, domu]

blob: 2b7286011b757f76f4f10647a0b394f637606e2c [file] [log] [blame]
thestig@chromium.orgb2f28d22012-03-03 01:54:351// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commitd7cae122008-07-26 21:49:384
brettw@chromium.orge3177dd52014-08-13 20:22:145#include "base/files/file_util.h"
initial.commitd7cae122008-07-26 21:49:386
Xiaohan Wangb705a64a2022-01-15 18:31:137#include "build/build_config.h"
8
9#if BUILDFLAG(IS_WIN)
jeremy@chromium.orgc2c998c2009-01-27 19:08:3910#include <io.h>
11#endif
mark@chromium.org836f1342008-10-01 17:40:1312#include <stdio.h>
13
initial.commitd7cae122008-07-26 21:49:3814#include <fstream>
kaliamoorthi@chromium.org0710fdd2014-02-18 16:31:5115#include <limits>
Victor Costanb5a0a97002019-09-08 04:55:1516#include <memory>
Victor Hugo Vianna Silva05f14542021-08-05 16:08:4817#include <vector>
initial.commitd7cae122008-07-26 21:49:3818
Hans Wennborgc3cffa62020-04-27 10:09:1219#include "base/check_op.h"
brettw@chromium.org25a4c1c2013-06-08 04:53:3620#include "base/files/file_enumerator.h"
brettw@chromium.org57999812013-02-24 05:40:5221#include "base/files/file_path.h"
Greg Thompson3f7e20f42020-05-02 19:01:1122#include "base/posix/eintr_wrapper.h"
tfarina@chromium.orgeb62f7262013-03-30 14:29:0023#include "base/strings/string_piece.h"
avi@chromium.org251cd6e52013-06-11 13:36:3724#include "base/strings/string_util.h"
25#include "base/strings/stringprintf.h"
avi@chromium.orga4ea1f12013-06-07 18:37:0726#include "base/strings/utf_string_conversions.h"
Etienne Pierre-Doray1da58592018-09-21 14:47:2027#include "base/threading/scoped_blocking_call.h"
avi543540e2015-12-24 05:15:3228#include "build/build_config.h"
estade@chromium.orgb9e04f02008-11-27 04:03:5729
Xiaohan Wangb705a64a2022-01-15 18:31:1330#if BUILDFLAG(IS_WIN)
Bruce Dawson1ad438d2021-07-09 20:10:0331#include <windows.h>
32#endif
33
brettw@chromium.org0408c752013-06-22 22:15:4634namespace base {
brettw@chromium.org04af979a2013-02-16 04:12:2635
Xiaohan Wangb705a64a2022-01-15 18:31:1336#if !BUILDFLAG(IS_WIN)
Lei Zhange3aa0b9a2020-06-11 08:59:2337OnceCallback<void(const FilePath&)> GetDeleteFileCallback() {
Lei Zhang9382efe2020-07-25 20:52:1438 return BindOnce(IgnoreResult(&DeleteFile));
Lei Zhange3aa0b9a2020-06-11 08:59:2339}
Xiaohan Wangb705a64a2022-01-15 18:31:1340#endif // !BUILDFLAG(IS_WIN)
Lei Zhange3aa0b9a2020-06-11 08:59:2341
Lei Zhang3190449f2020-06-12 05:14:0442OnceCallback<void(const FilePath&)> GetDeletePathRecursivelyCallback() {
Lei Zhang746ce472020-07-01 04:39:4543 return BindOnce(IgnoreResult(&DeletePathRecursively));
Lei Zhang3190449f2020-06-12 05:14:0444}
45
avi543540e2015-12-24 05:15:3246int64_t ComputeDirectorySize(const FilePath& root_path) {
47 int64_t running_size = 0;
brettw@chromium.org0408c752013-06-22 22:15:4648 FileEnumerator file_iter(root_path, true, FileEnumerator::FILES);
49 while (!file_iter.Next().empty())
50 running_size += file_iter.GetInfo().GetSize();
51 return running_size;
52}
53
brettw@chromium.org5553d5b2013-07-01 23:07:3654bool Move(const FilePath& from_path, const FilePath& to_path) {
55 if (from_path.ReferencesParent() || to_path.ReferencesParent())
56 return false;
brettw@chromium.orgf0ff2ad2013-07-09 17:42:2657 return internal::MoveUnsafe(from_path, to_path);
58}
59
Alexander Bolodurin53bfc89c22020-11-25 22:43:2960bool CopyFileContents(File& infile, File& outfile) {
Xiaohan Wangb705a64a2022-01-15 18:31:1361#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
Brian Geffon591e8f22021-04-08 18:33:2362 bool retry_slow = false;
63 bool res =
64 internal::CopyFileContentsWithSendfile(infile, outfile, retry_slow);
65 if (res || !retry_slow) {
66 return res;
67 }
68 // Any failures which allow retrying using read/write will not have modified
69 // either file offset or size.
70#endif
71
Alexander Bolodurin53bfc89c22020-11-25 22:43:2972 static constexpr size_t kBufferSize = 32768;
73 std::vector<char> buffer(kBufferSize);
74
75 for (;;) {
76 int bytes_read = infile.ReadAtCurrentPos(buffer.data(), buffer.size());
77 if (bytes_read < 0) {
78 return false;
79 }
80 if (bytes_read == 0) {
81 return true;
82 }
83 // Allow for partial writes
84 int bytes_written_per_read = 0;
85 do {
86 int bytes_written_partial = outfile.WriteAtCurrentPos(
87 &buffer[bytes_written_per_read], bytes_read - bytes_written_per_read);
88 if (bytes_written_partial < 0) {
89 return false;
90 }
91
92 bytes_written_per_read += bytes_written_partial;
93 } while (bytes_written_per_read < bytes_read);
94 }
95
96 NOTREACHED();
97 return false;
98}
99
evanm@google.com640517f2008-10-30 23:54:04100bool ContentsEqual(const FilePath& filename1, const FilePath& filename2) {
initial.commitd7cae122008-07-26 21:49:38101 // We open the file in binary format even if they are text files because
102 // we are just comparing that bytes are exactly same in both files and not
103 // doing anything smart with text formatting.
Xiaohan Wangb705a64a2022-01-15 18:31:13104#if BUILDFLAG(IS_WIN)
Jan Wilken Dörrie9bb441d2019-11-01 17:48:40105 std::ifstream file1(filename1.value().c_str(),
erikkay@google.com5af2edb92008-08-08 20:16:08106 std::ios::in | std::ios::binary);
Jan Wilken Dörrie9bb441d2019-11-01 17:48:40107 std::ifstream file2(filename2.value().c_str(),
erikkay@google.com5af2edb92008-08-08 20:16:08108 std::ios::in | std::ios::binary);
Xiaohan Wangb705a64a2022-01-15 18:31:13109#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
jdoerrie983968a2019-01-29 12:54:41110 std::ifstream file1(filename1.value(), std::ios::in | std::ios::binary);
111 std::ifstream file2(filename2.value(), std::ios::in | std::ios::binary);
Xiaohan Wangb705a64a2022-01-15 18:31:13112#endif // BUILDFLAG(IS_WIN)
estade@chromium.orgb9e04f02008-11-27 04:03:57113
initial.commitd7cae122008-07-26 21:49:38114 // Even if both files aren't openable (and thus, in some sense, "equal"),
115 // any unusable file yields a result of "false".
116 if (!file1.is_open() || !file2.is_open())
117 return false;
118
119 const int BUFFER_SIZE = 2056;
120 char buffer1[BUFFER_SIZE], buffer2[BUFFER_SIZE];
121 do {
122 file1.read(buffer1, BUFFER_SIZE);
123 file2.read(buffer2, BUFFER_SIZE);
124
mark@chromium.orgb81637c32009-06-26 21:17:24125 if ((file1.eof() != file2.eof()) ||
initial.commitd7cae122008-07-26 21:49:38126 (file1.gcount() != file2.gcount()) ||
pkasting9cf9b942014-10-01 22:18:43127 (memcmp(buffer1, buffer2, static_cast<size_t>(file1.gcount())))) {
initial.commitd7cae122008-07-26 21:49:38128 file1.close();
129 file2.close();
130 return false;
131 }
mark@chromium.orgb81637c32009-06-26 21:17:24132 } while (!file1.eof() || !file2.eof());
initial.commitd7cae122008-07-26 21:49:38133
134 file1.close();
135 file2.close();
136 return true;
137}
138
mark@chromium.orgb81637c32009-06-26 21:17:24139bool TextContentsEqual(const FilePath& filename1, const FilePath& filename2) {
Xiaohan Wangb705a64a2022-01-15 18:31:13140#if BUILDFLAG(IS_WIN)
Jan Wilken Dörrie9bb441d2019-11-01 17:48:40141 std::ifstream file1(filename1.value().c_str(), std::ios::in);
142 std::ifstream file2(filename2.value().c_str(), std::ios::in);
Xiaohan Wangb705a64a2022-01-15 18:31:13143#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
jdoerrie983968a2019-01-29 12:54:41144 std::ifstream file1(filename1.value(), std::ios::in);
145 std::ifstream file2(filename2.value(), std::ios::in);
Xiaohan Wangb705a64a2022-01-15 18:31:13146#endif // BUILDFLAG(IS_WIN)
mark@chromium.orgb81637c32009-06-26 21:17:24147
148 // Even if both files aren't openable (and thus, in some sense, "equal"),
149 // any unusable file yields a result of "false".
150 if (!file1.is_open() || !file2.is_open())
151 return false;
152
153 do {
154 std::string line1, line2;
155 getline(file1, line1);
156 getline(file2, line2);
157
158 // Check for mismatched EOF states, or any error state.
159 if ((file1.eof() != file2.eof()) ||
160 file1.bad() || file2.bad()) {
161 return false;
162 }
163
164 // Trim all '\r' and '\n' characters from the end of the line.
165 std::string::size_type end1 = line1.find_last_not_of("\r\n");
166 if (end1 == std::string::npos)
167 line1.clear();
168 else if (end1 + 1 < line1.length())
169 line1.erase(end1 + 1);
170
171 std::string::size_type end2 = line2.find_last_not_of("\r\n");
172 if (end2 == std::string::npos)
173 line2.clear();
174 else if (end2 + 1 < line2.length())
175 line2.erase(end2 + 1);
176
177 if (line1 != line2)
178 return false;
179 } while (!file1.eof() || !file2.eof());
180
181 return true;
182}
183
Greg Thompson3f7e20f42020-05-02 19:01:11184bool ReadStreamToString(FILE* stream, std::string* contents) {
185 return ReadStreamToStringWithMaxSize(
186 stream, std::numeric_limits<size_t>::max(), contents);
187}
188
189bool ReadStreamToStringWithMaxSize(FILE* stream,
190 size_t max_size,
191 std::string* contents) {
kaliamoorthi@chromium.org0710fdd2014-02-18 16:31:51192 if (contents)
193 contents->clear();
Abhijith Nair1b5b6ee22021-11-18 21:01:59194 if (!stream)
195 return false;
Greg Thompson3f7e20f42020-05-02 19:01:11196 // Seeking to the beginning is best-effort -- it is expected to fail for
197 // certain non-file stream (e.g., pipes).
198 HANDLE_EINTR(fseek(stream, 0, SEEK_SET));
199
200 // Many files have incorrect size (proc files etc). Hence, the file is read
201 // sequentially as opposed to a one-shot read, using file size as a hint for
202 // chunk size if available.
Mikhail Istomin1ede1552018-05-16 17:40:24203 constexpr int64_t kDefaultChunkSize = 1 << 16;
Greg Thompson3f7e20f42020-05-02 19:01:11204 int64_t chunk_size = kDefaultChunkSize - 1;
Greg Thompson3f7e20f42020-05-02 19:01:11205 ScopedBlockingCall scoped_blocking_call(FROM_HERE, BlockingType::MAY_BLOCK);
Xiaohan Wangb705a64a2022-01-15 18:31:13206#if BUILDFLAG(IS_WIN)
Greg Thompson3f7e20f42020-05-02 19:01:11207 BY_HANDLE_FILE_INFORMATION file_info = {};
208 if (::GetFileInformationByHandle(
209 reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(stream))),
210 &file_info)) {
211 LARGE_INTEGER size;
212 size.HighPart = file_info.nFileSizeHigh;
213 size.LowPart = file_info.nFileSizeLow;
214 if (size.QuadPart > 0)
215 chunk_size = size.QuadPart;
216 }
Xiaohan Wangb705a64a2022-01-15 18:31:13217#else // BUILDFLAG(IS_WIN)
Anand K Mistry53fa72d2021-07-15 01:15:26218 // In cases where the reported file size is 0, use a smaller chunk size to
219 // minimize memory allocated and cost of string::resize() in case the read
220 // size is small (i.e. proc files). If the file is larger than this, the read
221 // loop will reset |chunk_size| to kDefaultChunkSize.
222 constexpr int64_t kSmallChunkSize = 4096;
223 chunk_size = kSmallChunkSize - 1;
Greg Thompson3f7e20f42020-05-02 19:01:11224 stat_wrapper_t file_info = {};
225 if (!File::Fstat(fileno(stream), &file_info) && file_info.st_size > 0)
226 chunk_size = file_info.st_size;
Xiaohan Wangb705a64a2022-01-15 18:31:13227#endif // BUILDFLAG(IS_WIN)
Mikhail Istomin1ede1552018-05-16 17:40:24228 // We need to attempt to read at EOF for feof flag to be set so here we
229 // use |chunk_size| + 1.
230 chunk_size = std::min<uint64_t>(chunk_size, max_size) + 1;
Mikhail Istomin1ede1552018-05-16 17:40:24231 size_t bytes_read_this_pass;
232 size_t bytes_read_so_far = 0;
233 bool read_status = true;
234 std::string local_contents;
235 local_contents.resize(chunk_size);
kaliamoorthi@chromium.org0710fdd2014-02-18 16:31:51236
Mikhail Istomin1ede1552018-05-16 17:40:24237 while ((bytes_read_this_pass = fread(&local_contents[bytes_read_so_far], 1,
Greg Thompson3f7e20f42020-05-02 19:01:11238 chunk_size, stream)) > 0) {
Mikhail Istomin1ede1552018-05-16 17:40:24239 if ((max_size - bytes_read_so_far) < bytes_read_this_pass) {
240 // Read more than max_size bytes, bail out.
241 bytes_read_so_far = max_size;
kaliamoorthi@chromium.org0710fdd2014-02-18 16:31:51242 read_status = false;
243 break;
244 }
Mikhail Istomin1ede1552018-05-16 17:40:24245 // In case EOF was not reached, iterate again but revert to the default
246 // chunk size.
247 if (bytes_read_so_far == 0)
248 chunk_size = kDefaultChunkSize;
kaliamoorthi@chromium.org0710fdd2014-02-18 16:31:51249
Mikhail Istomin1ede1552018-05-16 17:40:24250 bytes_read_so_far += bytes_read_this_pass;
251 // Last fread syscall (after EOF) can be avoided via feof, which is just a
252 // flag check.
Greg Thompson3f7e20f42020-05-02 19:01:11253 if (feof(stream))
Mikhail Istomin1ede1552018-05-16 17:40:24254 break;
255 local_contents.resize(bytes_read_so_far + chunk_size);
initial.commitd7cae122008-07-26 21:49:38256 }
Greg Thompson3f7e20f42020-05-02 19:01:11257 read_status = read_status && !ferror(stream);
Mikhail Istomin1ede1552018-05-16 17:40:24258 if (contents) {
259 contents->swap(local_contents);
260 contents->resize(bytes_read_so_far);
261 }
initial.commitd7cae122008-07-26 21:49:38262
kaliamoorthi@chromium.org0710fdd2014-02-18 16:31:51263 return read_status;
264}
265
266bool ReadFileToString(const FilePath& path, std::string* contents) {
hashimoto6da2fef2016-02-24 03:39:58267 return ReadFileToStringWithMaxSize(path, contents,
268 std::numeric_limits<size_t>::max());
initial.commitd7cae122008-07-26 21:49:38269}
270
Greg Thompson3f7e20f42020-05-02 19:01:11271bool ReadFileToStringWithMaxSize(const FilePath& path,
272 std::string* contents,
273 size_t max_size) {
274 if (contents)
275 contents->clear();
276 if (path.ReferencesParent())
277 return false;
278 ScopedFILE file_stream(OpenFile(path, "rb"));
279 if (!file_stream)
280 return false;
281 return ReadStreamToStringWithMaxSize(file_stream.get(), max_size, contents);
282}
283
brettw@chromium.orgfb4bcfa32013-12-02 18:55:49284bool IsDirectoryEmpty(const FilePath& dir_path) {
285 FileEnumerator files(dir_path, false,
286 FileEnumerator::FILES | FileEnumerator::DIRECTORIES);
287 if (files.Next().empty())
288 return true;
289 return false;
290}
291
Greg Thompson3f7e20f42020-05-02 19:01:11292bool CreateTemporaryFile(FilePath* path) {
293 FilePath temp_dir;
294 return GetTempDir(&temp_dir) && CreateTemporaryFileInDir(temp_dir, path);
295}
296
Greg Thompsonf75f5fb2020-04-30 08:13:25297ScopedFILE CreateAndOpenTemporaryStream(FilePath* path) {
brettw@chromium.org03d9afc02013-12-03 17:55:52298 FilePath directory;
299 if (!GetTempDir(&directory))
Ivan Kotenkova16212a52017-11-08 12:37:33300 return nullptr;
brettw@chromium.org03d9afc02013-12-03 17:55:52301
Greg Thompsonf75f5fb2020-04-30 08:13:25302 return CreateAndOpenTemporaryStreamInDir(directory, path);
brettw@chromium.org03d9afc02013-12-03 17:55:52303}
304
brettw@chromium.org426d1c92013-12-03 20:08:54305bool CreateDirectory(const FilePath& full_path) {
Ivan Kotenkova16212a52017-11-08 12:37:33306 return CreateDirectoryAndGetError(full_path, nullptr);
brettw@chromium.org426d1c92013-12-03 20:08:54307}
308
avi543540e2015-12-24 05:15:32309bool GetFileSize(const FilePath& file_path, int64_t* file_size) {
rvargas@chromium.org54124ed02014-01-07 10:06:58310 File::Info info;
brettw@chromium.org9eae4e62013-12-04 20:56:49311 if (!GetFileInfo(file_path, &info))
brettw@chromium.org56285702013-12-04 18:22:49312 return false;
313 *file_size = info.size;
314 return true;
315}
316
brettw@chromium.orgc0d508162013-12-04 22:49:00317bool TouchFile(const FilePath& path,
318 const Time& last_accessed,
319 const Time& last_modified) {
Alexei Svitkine670d67ee2021-11-01 21:51:49320 int flags = File::FLAG_OPEN | File::FLAG_WRITE_ATTRIBUTES;
brettw@chromium.orgc0d508162013-12-04 22:49:00321
Xiaohan Wangb705a64a2022-01-15 18:31:13322#if BUILDFLAG(IS_WIN)
brettw@chromium.orgc0d508162013-12-04 22:49:00323 // On Windows, FILE_FLAG_BACKUP_SEMANTICS is needed to open a directory.
324 if (DirectoryExists(path))
Alexei Svitkinec417b2cd2021-10-21 14:22:40325 flags |= File::FLAG_WIN_BACKUP_SEMANTICS;
Xiaohan Wangb705a64a2022-01-15 18:31:13326#elif BUILDFLAG(IS_FUCHSIA)
Wez432ea8d892019-03-31 01:17:08327 // On Fuchsia, we need O_RDONLY for directories, or O_WRONLY for files.
328 // TODO(https://crbug.com/947802): Find a cleaner workaround for this.
329 flags |= (DirectoryExists(path) ? File::FLAG_READ : File::FLAG_WRITE);
330#endif
brettw@chromium.orgc0d508162013-12-04 22:49:00331
rvargas@chromium.org54124ed02014-01-07 10:06:58332 File file(path, flags);
333 if (!file.IsValid())
334 return false;
brettw@chromium.orgc0d508162013-12-04 22:49:00335
rvargas@chromium.org54124ed02014-01-07 10:06:58336 return file.SetTimes(last_accessed, last_modified);
brettw@chromium.orgc0d508162013-12-04 22:49:00337}
338
mark@chromium.org836f1342008-10-01 17:40:13339bool CloseFile(FILE* file) {
Ivan Kotenkova16212a52017-11-08 12:37:33340 if (file == nullptr)
sidchat@google.coma1a19502008-10-21 17:14:45341 return true;
mark@chromium.org836f1342008-10-01 17:40:13342 return fclose(file) == 0;
343}
344
jeremy@chromium.orgc2c998c2009-01-27 19:08:39345bool TruncateFile(FILE* file) {
Ivan Kotenkova16212a52017-11-08 12:37:33346 if (file == nullptr)
jeremy@chromium.orgc2c998c2009-01-27 19:08:39347 return false;
348 long current_offset = ftell(file);
349 if (current_offset == -1)
350 return false;
Xiaohan Wangb705a64a2022-01-15 18:31:13351#if BUILDFLAG(IS_WIN)
jeremy@chromium.orgc2c998c2009-01-27 19:08:39352 int fd = _fileno(file);
353 if (_chsize(fd, current_offset) != 0)
354 return false;
355#else
356 int fd = fileno(file);
357 if (ftruncate(fd, current_offset) != 0)
358 return false;
359#endif
360 return true;
361}
362
Lei Zhangeebbef62020-05-05 20:16:05363bool WriteFile(const FilePath& filename, span<const uint8_t> data) {
364 int size = checked_cast<int>(data.size());
365 return WriteFile(filename, reinterpret_cast<const char*>(data.data()),
366 size) == size;
367}
368
369bool WriteFile(const FilePath& filename, StringPiece data) {
370 int size = checked_cast<int>(data.size());
371 return WriteFile(filename, data.data(), size) == size;
372}
373
Greg Thompsonb4abcb42019-08-23 01:42:56374int GetUniquePathNumber(const FilePath& path) {
375 DCHECK(!path.empty());
376 if (!PathExists(path))
Greg Thompson42373544a2019-08-14 10:11:10377 return 0;
378
379 std::string number;
380 for (int count = 1; count <= kMaxUniqueFiles; ++count) {
381 StringAppendF(&number, " (%d)", count);
Greg Thompsonb4abcb42019-08-23 01:42:56382 if (!PathExists(path.InsertBeforeExtensionASCII(number)))
Greg Thompson42373544a2019-08-14 10:11:10383 return count;
384 number.clear();
jam@chromium.orge285afa2012-01-31 23:16:39385 }
386
387 return -1;
388}
Bruce Longd096e482019-02-28 17:50:00389
390FilePath GetUniquePath(const FilePath& path) {
Greg Thompsonb4abcb42019-08-23 01:42:56391 DCHECK(!path.empty());
392 const int uniquifier = GetUniquePathNumber(path);
393 if (uniquifier > 0)
394 return path.InsertBeforeExtensionASCII(StringPrintf(" (%d)", uniquifier));
395 return uniquifier == 0 ? path : base::FilePath();
Bruce Longd096e482019-02-28 17:50:00396}
Victor Costanb5a0a97002019-09-08 04:55:15397
398namespace internal {
399
400bool PreReadFileSlow(const FilePath& file_path, int64_t max_bytes) {
401 DCHECK_GE(max_bytes, 0);
402
403 File file(file_path, File::FLAG_OPEN | File::FLAG_READ |
Alexei Svitkinec417b2cd2021-10-21 14:22:40404 File::FLAG_WIN_SEQUENTIAL_SCAN |
405 File::FLAG_WIN_SHARE_DELETE);
Victor Costanb5a0a97002019-09-08 04:55:15406 if (!file.IsValid())
407 return false;
408
409 constexpr int kBufferSize = 1024 * 1024;
410 // Ensures the buffer is deallocated at function exit.
411 std::unique_ptr<char[]> buffer_deleter(new char[kBufferSize]);
412 char* const buffer = buffer_deleter.get();
413
414 while (max_bytes > 0) {
415 // The static_cast<int> is safe because kBufferSize is int, and both values
416 // are non-negative. So, the minimum is guaranteed to fit in int.
417 const int read_size =
418 static_cast<int>(std::min<int64_t>(max_bytes, kBufferSize));
419 DCHECK_GE(read_size, 0);
420 DCHECK_LE(read_size, kBufferSize);
421
422 const int read_bytes = file.ReadAtCurrentPos(buffer, read_size);
423 if (read_bytes < 0)
424 return false;
425 if (read_bytes == 0)
426 break;
427
428 max_bytes -= read_bytes;
429 }
430
431 return true;
432}
433
434} // namespace internal
435
brettw@chromium.orga26f4ae2014-03-13 17:26:21436} // namespace base