| 3607 | -------------------------------------------------------------------------------*/ |
| 3608 | |
| 3609 | char* 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 | |
| 3630 | out_input_file: |
| 3631 | FileIO::close(input_file); |
| 3632 | return file_contents; |
| 3633 | } |
| 3634 | |
| 3635 | /*------------------------------------------------------------------------------- |
| 3636 |
no test coverage detected