Reads file data into the buffer Returns true on success Max file size

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
// Reads file data into the buffer.
// Returns true on success.
// Max file size <= min(max int, max vector::size_type)
BASE_EXPORT bool ReadFile(const FilePath& filename, std::vector<char>* data);
bool ReadFile(const FilePath& filename, std::vector<char>* data) {
DCHECK(data);
int64 file_size_64 = 0;
if (GetFileSize(filename, &file_size_64)) {
const int file_size = checked_cast<int>(file_size_64);
if (file_size > 0) {
data->resize(checked_cast<size_t>(file_size));
if (file_size == ReadFile(filename, data->data(), file_size)) {
return true;
}
}
}
return false;
}