MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / getFileText

Function getFileText

plugins/plugin_utils/plugin_files.cpp:366–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364}
365
366std::string getFileText(const char* file) {
367 std::string text;
368 if (!file) {
369 return text;
370 }
371
372 FILE* fp = fopen(convertPathToDelims(file).c_str(), "rb");
373 if (!fp) {
374 return text;
375 }
376
377 fseek(fp, 0, SEEK_END);
378 unsigned int i = (unsigned int)ftell(fp);
379 fseek(fp, 0, SEEK_SET);
380
381 char* temp = (char*)malloc(i + 1);
382 fread(temp, i, 1, fp);
383 temp[i] = 0;
384 text = temp;
385 free(temp);
386 fclose(fp);
387
388 return replace_all(text, "\r", std::string());
389}
390
391std::vector<std::string> getFileTextLines(const char* file) {
392 return tokenize(getFileText(file), "\n", 0, false);

Callers 1

getFileTextLinesFunction · 0.70

Calls 3

convertPathToDelimsFunction · 0.85
c_strMethod · 0.80
replace_allFunction · 0.70

Tested by

no test coverage detected