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

Function ImFileOpen

Dependencies/ImGui/src/imgui.cpp:2367–2389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2365#ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
2366
2367ImFileHandle ImFileOpen(const char* filename, const char* mode)
2368{
2369#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && (defined(__MINGW32__) || (!defined(__CYGWIN__) && !defined(__GNUC__)))
2370 // We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames.
2371 // Previously we used ImTextCountCharsFromUtf8/ImTextStrFromUtf8 here but we now need to support ImWchar16 and ImWchar32!
2372 const int filename_wsize = ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
2373 const int mode_wsize = ::MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0);
2374
2375 // Use stack buffer if possible, otherwise heap buffer. Sizes include zero terminator.
2376 // We don't rely on current ImGuiContext as this is implied to be a helper function which doesn't depend on it (see #7314).
2377 wchar_t local_temp_stack[FILENAME_MAX];
2378 ImVector<wchar_t> local_temp_heap;
2379 if (filename_wsize + mode_wsize > IM_ARRAYSIZE(local_temp_stack))
2380 local_temp_heap.resize(filename_wsize + mode_wsize);
2381 wchar_t* filename_wbuf = local_temp_heap.Data ? local_temp_heap.Data : local_temp_stack;
2382 wchar_t* mode_wbuf = filename_wbuf + filename_wsize;
2383 ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, filename_wbuf, filename_wsize);
2384 ::MultiByteToWideChar(CP_UTF8, 0, mode, -1, mode_wbuf, mode_wsize);
2385 return ::_wfopen(filename_wbuf, mode_wbuf);
2386#else
2387 return fopen(filename, mode);
2388#endif
2389}
2390
2391// We should in theory be using fseeko()/ftello() with off_t and _fseeki64()/_ftelli64() with __int64, waiting for the PR that does that in a very portable pre-C++11 zero-warnings way.
2392bool ImFileClose(ImFileHandle f) { return fclose(f) == 0; }

Callers 3

ImFileLoadToMemoryFunction · 0.70
LogToFileMethod · 0.70
SaveIniSettingsToDiskMethod · 0.70

Calls 1

resizeMethod · 0.45

Tested by

no test coverage detected