MCPcopy Create free account
hub / github.com/AlexandreRouma/SDRPlusPlus / ImFileLoadToMemory

Function ImFileLoadToMemory

core/src/imgui/imgui.cpp:1573–1610  ·  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

1571// Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree()
1572// This can't really be used with "rt" because fseek size won't match read size.
1573void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_file_size, int padding_bytes)
1574{
1575 IM_ASSERT(filename && mode);
1576 if (out_file_size)
1577 *out_file_size = 0;
1578
1579 ImFileHandle f;
1580 if ((f = ImFileOpen(filename, mode)) == NULL)
1581 return NULL;
1582
1583 size_t file_size = (size_t)ImFileGetSize(f);
1584 if (file_size == (size_t)-1)
1585 {
1586 ImFileClose(f);
1587 return NULL;
1588 }
1589
1590 void* file_data = IM_ALLOC(file_size + padding_bytes);
1591 if (file_data == NULL)
1592 {
1593 ImFileClose(f);
1594 return NULL;
1595 }
1596 if (ImFileRead(file_data, 1, file_size, f) != file_size)
1597 {
1598 ImFileClose(f);
1599 IM_FREE(file_data);
1600 return NULL;
1601 }
1602 if (padding_bytes > 0)
1603 memset((void*)(((char*)file_data) + file_size), 0, (size_t)padding_bytes);
1604
1605 ImFileClose(f);
1606 if (out_file_size)
1607 *out_file_size = file_size;
1608
1609 return file_data;
1610}
1611
1612//-----------------------------------------------------------------------------
1613// [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