Skip to content

Commit 45c00cf

Browse files
authored
Unicode support. (#2)
1 parent 847842c commit 45c00cf

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

PowerUtils/file.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
#pragma once
22

3+
#include <filesystem>
4+
#include <fstream>
35
#include <vector>
46

5-
inline std::vector<uint8_t> LoadFile(const char* path)
7+
inline std::vector<uint8_t> LoadFile(const std::filesystem::path& path)
68
{
7-
std::vector<uint8_t> data{};
8-
auto* stream = fopen(path, "rb");
9-
if (stream == nullptr)
9+
std::ifstream stream(path, std::ios::binary);
10+
if (!stream.is_open())
1011
{
1112
return {};
1213
}
1314

14-
fseek(stream, 0, SEEK_END);
15-
16-
const auto size = ftell(stream);
17-
18-
fseek(stream, 0, SEEK_SET);
15+
stream.seekg(0, std::ios::end);
16+
std::streampos size = stream.tellg();
17+
stream.seekg(0, std::ios::beg);
1918

19+
std::vector<uint8_t> data;
2020
data.resize(size);
21-
22-
fread(data.data(), 1, data.size(), stream);
23-
fclose(stream);
21+
stream.read((char *)(data.data()), size);
22+
if (stream.bad())
23+
{
24+
return {};
25+
}
2426

2527
return data;
2628
}

0 commit comments

Comments
 (0)