| 299 | |
| 300 | |
| 301 | std::vector<uint8_t> readFile(const std::string& path) { |
| 302 | std::vector<uint8_t> data; |
| 303 | FILE* f = std::fopen(path.c_str(), "rb"); |
| 304 | if (!f) |
| 305 | throw Exception("Cannot read file %s", path.c_str()); |
| 306 | DEFER({ |
| 307 | std::fclose(f); |
| 308 | }); |
| 309 | |
| 310 | // Get file size so we can make a single allocation |
| 311 | std::fseek(f, 0, SEEK_END); |
| 312 | size_t len = std::ftell(f); |
| 313 | std::fseek(f, 0, SEEK_SET); |
| 314 | |
| 315 | data.resize(len); |
| 316 | std::fread(data.data(), 1, len, f); |
| 317 | return data; |
| 318 | } |
| 319 | |
| 320 | |
| 321 | uint8_t* readFile(const std::string& path, size_t* size) { |