MCPcopy Create free account
hub / github.com/PenguLoader/PenguLoader / read_file

Method read_file

core/src/utils/file.cc:55–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55bool 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
81bool file::write_file(const path &path, const void *buffer, size_t length)
82{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected