MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / LoadText

Function LoadText

Source/XML/xml_helper.cpp:215–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

213}
214
215bool 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
242bool LoadTextRetryable(void *&mem,
243 const std::string &path,

Callers 2

LoadMethod · 0.85
LoadTextRetryableFunction · 0.85

Calls 2

my_fopenFunction · 0.85
FatalErrorFunction · 0.50

Tested by

no test coverage detected