25 lines
443 B
C
Raw Normal View History

2024-09-07 18:00:09 +06:00
#pragma once
#include <vector>
inline static std::vector<uint8_t> LoadFile(const char* path)
{
2024-09-07 18:21:08 +06:00
std::vector<uint8_t> data{};
auto* stream = fopen(path, "rb");
if (stream == nullptr)
{
return data;
}
2024-09-07 18:00:09 +06:00
2024-09-07 18:21:08 +06:00
fseek(stream, 0, SEEK_END);
2024-09-07 18:00:09 +06:00
2024-09-07 18:21:08 +06:00
const auto size = ftell(stream);
2024-09-07 18:00:09 +06:00
2024-09-07 18:21:08 +06:00
fseek(stream, 0, SEEK_SET);
2024-09-07 18:00:09 +06:00
2024-09-07 18:21:08 +06:00
data.resize(size);
2024-09-07 18:00:09 +06:00
2024-09-07 18:21:08 +06:00
fread(data.data(), 1, data.size(), stream);
fclose(stream);
2024-09-07 18:00:09 +06:00
2024-09-07 18:21:08 +06:00
return data;
2024-09-07 18:00:09 +06:00
}