MCPcopy Create free account
hub / github.com/cinder/Cinder / ImFileOpen

Function ImFileOpen

src/imgui/imgui.cpp:2408–2430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2406#ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
2407
2408ImFileHandle ImFileOpen(const char* filename, const char* mode)
2409{
2410#if defined(_WIN32) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) && (defined(__MINGW32__) || (!defined(__CYGWIN__) && !defined(__GNUC__)))
2411 // We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames.
2412 // Previously we used ImTextCountCharsFromUtf8/ImTextStrFromUtf8 here but we now need to support ImWchar16 and ImWchar32!
2413 const int filename_wsize = ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, NULL, 0);
2414 const int mode_wsize = ::MultiByteToWideChar(CP_UTF8, 0, mode, -1, NULL, 0);
2415
2416 // Use stack buffer if possible, otherwise heap buffer. Sizes include zero terminator.
2417 // We don't rely on current ImGuiContext as this is implied to be a helper function which doesn't depend on it (see #7314).
2418 wchar_t local_temp_stack[FILENAME_MAX];
2419 ImVector<wchar_t> local_temp_heap;
2420 if (filename_wsize + mode_wsize > IM_ARRAYSIZE(local_temp_stack))
2421 local_temp_heap.resize(filename_wsize + mode_wsize);
2422 wchar_t* filename_wbuf = local_temp_heap.Data ? local_temp_heap.Data : local_temp_stack;
2423 wchar_t* mode_wbuf = filename_wbuf + filename_wsize;
2424 ::MultiByteToWideChar(CP_UTF8, 0, filename, -1, filename_wbuf, filename_wsize);
2425 ::MultiByteToWideChar(CP_UTF8, 0, mode, -1, mode_wbuf, mode_wsize);
2426 return ::_wfopen(filename_wbuf, mode_wbuf);
2427#else
2428 return fopen(filename, mode);
2429#endif
2430}
2431
2432// 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.
2433bool 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