| 53 | } |
| 54 | |
| 55 | bool file::read_file(const path &path, void **buffer, size_t *length) |
| 56 | { |
| 57 | #if OS_WIN |
| 58 | FILE* fp = _wfopen(path.c_str(), L"rb"); |
| 59 | #else |
| 60 | FILE* fp = fopen(path.c_str(), "rb"); |
| 61 | #endif |
| 62 | if (fp != nullptr) |
| 63 | { |
| 64 | fseek(fp, 0, SEEK_END); |
| 65 | long size = ftell(fp); |
| 66 | fseek(fp, 0, SEEK_SET); |
| 67 | |
| 68 | *buffer = malloc(size + 1); |
| 69 | if (length) *length = size; |
| 70 | |
| 71 | fread(*buffer, 1, size, fp); |
| 72 | reinterpret_cast<uint8_t *>(*buffer)[size] = '\0'; |
| 73 | |
| 74 | fclose(fp); |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | bool file::write_file(const path &path, const void *buffer, size_t length) |
| 82 | { |
nothing calls this directly
no outgoing calls
no test coverage detected