MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / ImFileLoadToMemory

Function ImFileLoadToMemory

Dependencies/ImGui/src/imgui.cpp:2401–2438  ·  view source on GitHub ↗

Helper: Load file content into memory Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree() This can't really be used with "rt" because fseek size won't match read size.

Source from the content-addressed store, hash-verified

2399// Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree()
2400// This can't really be used with "rt" because fseek size won't match read size.
2401void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_file_size, int padding_bytes)
2402{
2403 IM_ASSERT(filename && mode);
2404 if (out_file_size)
2405 *out_file_size = 0;
2406
2407 ImFileHandle f;
2408 if ((f = ImFileOpen(filename, mode)) == NULL)
2409 return NULL;
2410
2411 size_t file_size = (size_t)ImFileGetSize(f);
2412 if (file_size == (size_t)-1)
2413 {
2414 ImFileClose(f);
2415 return NULL;
2416 }
2417
2418 void* file_data = IM_ALLOC(file_size + padding_bytes);
2419 if (file_data == NULL)
2420 {
2421 ImFileClose(f);
2422 return NULL;
2423 }
2424 if (ImFileRead(file_data, 1, file_size, f) != file_size)
2425 {
2426 ImFileClose(f);
2427 IM_FREE(file_data);
2428 return NULL;
2429 }
2430 if (padding_bytes > 0)
2431 memset((void*)(((char*)file_data) + file_size), 0, (size_t)padding_bytes);
2432
2433 ImFileClose(f);
2434 if (out_file_size)
2435 *out_file_size = file_size;
2436
2437 return file_data;
2438}
2439
2440//-----------------------------------------------------------------------------
2441// [SECTION] MISC HELPERS/UTILITIES (ImText* functions)

Callers 2

AddFontFromFileTTFMethod · 0.85

Calls 4

ImFileOpenFunction · 0.70
ImFileGetSizeFunction · 0.70
ImFileCloseFunction · 0.70
ImFileReadFunction · 0.70

Tested by

no test coverage detected