| 150 | } |
| 151 | |
| 152 | std::string ReadFileUtf8(const std::string& path) { |
| 153 | FILE* fp = OpenFileUtf8(path, "rb"); |
| 154 | if (fp == nullptr) { |
| 155 | throw FileNotFound(path); |
| 156 | } |
| 157 | |
| 158 | std::string content; |
| 159 | char buffer[4096]; |
| 160 | for (;;) { |
| 161 | const size_t read = fread(buffer, 1, sizeof(buffer), fp); |
| 162 | if (read > 0) { |
| 163 | content.append(buffer, read); |
| 164 | } |
| 165 | if (read < sizeof(buffer)) { |
| 166 | if (ferror(fp)) { |
| 167 | fclose(fp); |
| 168 | throw FileNotFound(path); |
| 169 | } |
| 170 | break; |
| 171 | } |
| 172 | } |
| 173 | fclose(fp); |
| 174 | return content; |
| 175 | } |
| 176 | |
| 177 | #if defined(_WIN32) || defined(_WIN64) |
| 178 | using internal::Utf8FromWide; |
no test coverage detected