From c4959bf520a0eecb2495f64e999878c30ac5bdf5 Mon Sep 17 00:00:00 2001 From: chiteroman Date: Sun, 18 Aug 2024 00:05:19 +0200 Subject: [PATCH] Refine readFile logic --- app/src/main/cpp/main.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/src/main/cpp/main.cpp b/app/src/main/cpp/main.cpp index 6decb85..f18404c 100644 --- a/app/src/main/cpp/main.cpp +++ b/app/src/main/cpp/main.cpp @@ -267,27 +267,21 @@ private: }; static std::vector readFile(const char *path) { - - std::vector vector; - FILE *file = fopen(path, "rb"); - if (file) { - fseek(file, 0, SEEK_END); - long size = ftell(file); - fseek(file, 0, SEEK_SET); + if (!file) return {}; - vector.resize(size); - fread(vector.data(), 1, size, file); - fclose(file); - } else { - LOGD("Couldn't read %s file!", path); - } + auto size = std::filesystem::file_size(path); + + std::vector vector(size); + + fread(vector.data(), 1, size, file); + + fclose(file); return vector; } - static void companion(int fd) { std::vector dex, json;