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.
| 1916 | // Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree() |
| 1917 | // This can't really be used with "rt" because fseek size won't match read size. |
| 1918 | void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_file_size, int padding_bytes) |
| 1919 | { |
| 1920 | IM_ASSERT(filename && mode); |
| 1921 | if (out_file_size) |
| 1922 | *out_file_size = 0; |
| 1923 | |
| 1924 | ImFileHandle f; |
| 1925 | if ((f = ImFileOpen(filename, mode)) == NULL) |
| 1926 | return NULL; |
| 1927 | |
| 1928 | size_t file_size = (size_t)ImFileGetSize(f); |
| 1929 | if (file_size == (size_t)-1) |
| 1930 | { |
| 1931 | ImFileClose(f); |
| 1932 | return NULL; |
| 1933 | } |
| 1934 | |
| 1935 | void* file_data = IM_ALLOC(file_size + padding_bytes); |
| 1936 | if (file_data == NULL) |
| 1937 | { |
| 1938 | ImFileClose(f); |
| 1939 | return NULL; |
| 1940 | } |
| 1941 | if (ImFileRead(file_data, 1, file_size, f) != file_size) |
| 1942 | { |
| 1943 | ImFileClose(f); |
| 1944 | IM_FREE(file_data); |
| 1945 | return NULL; |
| 1946 | } |
| 1947 | if (padding_bytes > 0) |
| 1948 | memset((void*)(((char*)file_data) + file_size), 0, (size_t)padding_bytes); |
| 1949 | |
| 1950 | ImFileClose(f); |
| 1951 | if (out_file_size) |
| 1952 | *out_file_size = file_size; |
| 1953 | |
| 1954 | return file_data; |
| 1955 | } |
| 1956 | |
| 1957 | //----------------------------------------------------------------------------- |
| 1958 | // [SECTION] MISC HELPERS/UTILITIES (ImText* functions) |
no test coverage detected