Refine readFile logic

This commit is contained in:
chiteroman 2024-08-18 00:05:19 +02:00
parent 372be7e799
commit c4959bf520
No known key found for this signature in database

View File

@ -267,27 +267,21 @@ private:
}; };
static std::vector<uint8_t> readFile(const char *path) { static std::vector<uint8_t> readFile(const char *path) {
std::vector<uint8_t> vector;
FILE *file = fopen(path, "rb"); FILE *file = fopen(path, "rb");
if (file) { if (!file) return {};
fseek(file, 0, SEEK_END);
long size = ftell(file);
fseek(file, 0, SEEK_SET);
vector.resize(size); auto size = std::filesystem::file_size(path);
fread(vector.data(), 1, size, file);
fclose(file); std::vector<uint8_t> vector(size);
} else {
LOGD("Couldn't read %s file!", path); fread(vector.data(), 1, size, file);
}
fclose(file);
return vector; return vector;
} }
static void companion(int fd) { static void companion(int fd) {
std::vector<uint8_t> dex, json; std::vector<uint8_t> dex, json;