From dd7d3777ad10373d0eeb23c118e4bdcfc7464494 Mon Sep 17 00:00:00 2001 From: _xeroxz <_xeroxz@back.engineer> Date: Wed, 1 Dec 2021 01:45:00 -0800 Subject: [PATCH] added open_binary_file to vmutils.hpp --- include/vmutils.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/vmutils.hpp b/include/vmutils.hpp index 163d755..4212a64 100644 --- a/include/vmutils.hpp +++ b/include/vmutils.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -94,6 +95,23 @@ inline void init() { } } +inline bool open_binary_file(const std::string &file, + std::vector &data) { + std::ifstream fstr(file, std::ios::binary); + if (!fstr.is_open()) return false; + + fstr.unsetf(std::ios::skipws); + fstr.seekg(0, std::ios::end); + + const auto file_size = fstr.tellg(); + + fstr.seekg(NULL, std::ios::beg); + data.reserve(static_cast(file_size)); + data.insert(data.begin(), std::istream_iterator(fstr), + std::istream_iterator()); + return true; +} + /// /// utils pertaining to native registers... ///