Try to appease android's crappy toolchain

pull/2005/head
Jason Rhinelander 2 years ago
parent 75e382604b
commit fae527517d
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262

@ -19,24 +19,23 @@
namespace llarp::util namespace llarp::util
{ {
static std::pair<fs::ifstream, std::streampos> static std::streampos
slurp_file_open(const fs::path& filename) slurp_file_open(const fs::path& filename, fs::ifstream& in)
{ {
std::pair<fs::ifstream, std::streampos> f;
auto& [in, size] = f;
in.exceptions(std::ifstream::failbit | std::ifstream::badbit); in.exceptions(std::ifstream::failbit | std::ifstream::badbit);
in.open(filename, std::ios::binary | std::ios::in); in.open(filename, std::ios::binary | std::ios::in);
in.seekg(0, std::ios::end); in.seekg(0, std::ios::end);
size = in.tellg(); auto size = in.tellg();
in.seekg(0, std::ios::beg); in.seekg(0, std::ios::beg);
return f; return size;
} }
std::string std::string
slurp_file(const fs::path& filename) slurp_file(const fs::path& filename)
{ {
fs::ifstream in;
std::string contents; std::string contents;
auto [in, size] = slurp_file_open(filename); auto size = slurp_file_open(filename, in);
contents.resize(size); contents.resize(size);
in.read(contents.data(), size); in.read(contents.data(), size);
return contents; return contents;
@ -45,7 +44,8 @@ namespace llarp::util
size_t size_t
slurp_file(const fs::path& filename, char* buffer, size_t buffer_size) slurp_file(const fs::path& filename, char* buffer, size_t buffer_size)
{ {
auto [in, size] = slurp_file_open(filename); fs::ifstream in;
auto size = slurp_file_open(filename, in);
if (static_cast<size_t>(size) > buffer_size) if (static_cast<size_t>(size) > buffer_size)
throw std::length_error{"file is too large for buffer"}; throw std::length_error{"file is too large for buffer"};
in.read(buffer, size); in.read(buffer, size);

Loading…
Cancel
Save