MCPcopy Create free account
hub / github.com/TurningWheel/Barony / readFile

Function readFile

src/files.cpp:3609–3633  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3607-------------------------------------------------------------------------------*/
3608
3609char* readFile(char* filename)
3610{
3611 long input_file_size = 0;
3612 char* file_contents = NULL;
3613 File* input_file = openDataFile(filename, "rb");
3614 if (!input_file) {
3615 printlog("Open failed: %s", strerror(errno));
3616 goto out_input_file;
3617 }
3618
3619 input_file_size = input_file->size();
3620 if (input_file_size > (1<<30)) {
3621 printlog("Unreasonable size: %ld", input_file_size);
3622 goto out_input_file;
3623 }
3624
3625 input_file->seek(0, File::SeekMode::SET);
3626 file_contents = static_cast<char*>(malloc((input_file_size + 1) * sizeof(char)));
3627 input_file->read(file_contents, sizeof(char), input_file_size);
3628 file_contents[input_file_size] = 0;
3629
3630out_input_file:
3631 FileIO::close(input_file);
3632 return file_contents;
3633}
3634
3635/*-------------------------------------------------------------------------------
3636

Callers 2

readBooksIntoTempMethod · 0.85
createBookMethod · 0.85

Calls 5

openDataFileFunction · 0.85
printlogFunction · 0.85
seekMethod · 0.80
sizeMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected