From bf9ada75b941b40f30dfb25b063e064be062b7d8 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 4 Jan 2023 16:14:49 +0100 Subject: Support reading from /proc --- file.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'file.cpp') diff --git a/file.cpp b/file.cpp index 0c28511..4e10035 100644 --- a/file.cpp +++ b/file.cpp @@ -8,10 +8,16 @@ using namespace std::string_literals; std::string Reichwein::File::getFile(const fs::path& filename) { - std::ifstream file(filename.string(), std::ios::in | std::ios::binary | std::ios::ate); + std::ifstream file(filename.string(), std::ios::in | std::ios::binary); if (file.is_open()) { + file.seekg(0, std::ios::end); std::ifstream::pos_type fileSize = file.tellg(); + if (fileSize < 0) { // on pseudo-files (e.g. /proc/*), this doesn't work. Use a slower workaround: + std::stringstream buffer; + buffer << file.rdbuf(); + return buffer.str(); + } file.seekg(0, std::ios::beg); std::string bytes(fileSize, ' '); -- cgit v1.2.3