| 213 | } |
| 214 | |
| 215 | bool LoadText(void *&mem, const char *path) { |
| 216 | FILE *file = my_fopen(path, "rb"); |
| 217 | if (!file) { |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | fseek(file, 0, SEEK_END); |
| 222 | long file_size = ftell(file); |
| 223 | rewind(file); |
| 224 | |
| 225 | mem = OG_MALLOC(file_size + 1); |
| 226 | if (!mem) { |
| 227 | FatalError("Error", "Could not allocate memory for file: %s", path); |
| 228 | } |
| 229 | size_t read = fread(mem, 1, file_size, file); |
| 230 | |
| 231 | if (read != file_size) { |
| 232 | LOGW << "Read less than ftell told us we would!" << std::endl; |
| 233 | } |
| 234 | |
| 235 | ((char *)mem)[read] = '\0'; |
| 236 | |
| 237 | fclose(file); |
| 238 | |
| 239 | return true; |
| 240 | } |
| 241 | |
| 242 | bool LoadTextRetryable(void *&mem, |
| 243 | const std::string &path, |
no test coverage detected