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.
| 1783 | // Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree() |
| 1784 | // This can't really be used with "rt" because fseek size won't match read size. |
| 1785 | void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_file_size, int padding_bytes) |
| 1786 | { |
| 1787 | IM_ASSERT(filename && mode); |
| 1788 | if (out_file_size) |
| 1789 | *out_file_size = 0; |
| 1790 | |
| 1791 | ImFileHandle f; |
| 1792 | if ((f = ImFileOpen(filename, mode)) == NULL) |
| 1793 | return NULL; |
| 1794 | |
| 1795 | size_t file_size = (size_t)ImFileGetSize(f); |
| 1796 | if (file_size == (size_t)-1) |
| 1797 | { |
| 1798 | ImFileClose(f); |
| 1799 | return NULL; |
| 1800 | } |
| 1801 | |
| 1802 | void* file_data = IM_ALLOC(file_size + padding_bytes); |
| 1803 | if (file_data == NULL) |
| 1804 | { |
| 1805 | ImFileClose(f); |
| 1806 | return NULL; |
| 1807 | } |
| 1808 | if (ImFileRead(file_data, 1, file_size, f) != file_size) |
| 1809 | { |
| 1810 | ImFileClose(f); |
| 1811 | IM_FREE(file_data); |
| 1812 | return NULL; |
| 1813 | } |
| 1814 | if (padding_bytes > 0) |
| 1815 | memset((void*)(((char*)file_data) + file_size), 0, (size_t)padding_bytes); |
| 1816 | |
| 1817 | ImFileClose(f); |
| 1818 | if (out_file_size) |
| 1819 | *out_file_size = file_size; |
| 1820 | |
| 1821 | return file_data; |
| 1822 | } |
| 1823 | |
| 1824 | //----------------------------------------------------------------------------- |
| 1825 | // [SECTION] MISC HELPERS/UTILITIES (ImText* functions) |
no test coverage detected