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.
| 1800 | // Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree() |
| 1801 | // This can't really be used with "rt" because fseek size won't match read size. |
| 1802 | void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_file_size, int padding_bytes) |
| 1803 | { |
| 1804 | IM_ASSERT(filename && mode); |
| 1805 | if (out_file_size) |
| 1806 | *out_file_size = 0; |
| 1807 | |
| 1808 | ImFileHandle f; |
| 1809 | if ((f = ImFileOpen(filename, mode)) == NULL) |
| 1810 | return NULL; |
| 1811 | |
| 1812 | size_t file_size = (size_t)ImFileGetSize(f); |
| 1813 | if (file_size == (size_t)-1) |
| 1814 | { |
| 1815 | ImFileClose(f); |
| 1816 | return NULL; |
| 1817 | } |
| 1818 | |
| 1819 | void* file_data = IM_ALLOC(file_size + padding_bytes); |
| 1820 | if (file_data == NULL) |
| 1821 | { |
| 1822 | ImFileClose(f); |
| 1823 | return NULL; |
| 1824 | } |
| 1825 | if (ImFileRead(file_data, 1, file_size, f) != file_size) |
| 1826 | { |
| 1827 | ImFileClose(f); |
| 1828 | IM_FREE(file_data); |
| 1829 | return NULL; |
| 1830 | } |
| 1831 | if (padding_bytes > 0) |
| 1832 | memset((void*)(((char*)file_data) + file_size), 0, (size_t)padding_bytes); |
| 1833 | |
| 1834 | ImFileClose(f); |
| 1835 | if (out_file_size) |
| 1836 | *out_file_size = file_size; |
| 1837 | |
| 1838 | return file_data; |
| 1839 | } |
| 1840 | |
| 1841 | //----------------------------------------------------------------------------- |
| 1842 | // [SECTION] MISC HELPERS/UTILITIES (ImText* functions) |
no test coverage detected