1 // Copyright 2023 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "file_util.h" 6 7 #include <fstream> 8 #include <iostream> 9 #include <streambuf> 10 #include <string> 11 12 namespace bssl { 13 14 namespace fillins { 15 ReadFileToString(const FilePath & path,std::string * out)16bool ReadFileToString(const FilePath &path, std::string *out) { 17 std::ifstream file(path.value(), std::ios::binary); 18 file.unsetf(std::ios::skipws); 19 20 file.seekg(0, std::ios::end); 21 if (file.tellg() <= 0) { 22 return false; 23 } 24 out->reserve(file.tellg()); 25 file.seekg(0, std::ios::beg); 26 27 out->assign(std::istreambuf_iterator<char>(file), 28 std::istreambuf_iterator<char>()); 29 30 return true; 31 } 32 33 } // namespace fillins 34 35 } // namespace bssl 36