Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing support for mingw toolchains that target the newer ucrt #642

Merged
merged 2 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,12 @@ macro(commom_lib_settings lib write)
lib/internalexport_mingw.def
$<${write}:lib/internalexport_write_mingw.def>
)
# Need these flags if mingw happens to target the ucrt (new) rather
# than the legacy msvcrt. Otherwise tests will fail to run because
# the necessary dlls will be missing. If we statically link
# them instead it's fine. This does not cause any abberations if
# the mingw toolchain targets msvcrt instead.
target_link_options(${lib} PUBLIC -static-libgcc -static-libstdc++)
else()
target_sources(
${lib}
Expand Down
14 changes: 7 additions & 7 deletions lib/filestream.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ KTX_error_code ktxFileStream_getsize(ktxStream* str, ktx_size_t* size)

assert(str->type == eStreamTypeFile);

// Need to flush so that fstat will return the current size.
// Can ignore return value. The only error that can happen is to tell you
// it was a NOP because the file is read only.
#if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(__MINGW32__)
// Bug in VS2013 msvcrt. fflush on FILE open for READ changes file offset
// to 4096.
if (str->data.file->_flag & _IOWRT)
// Need to flush so that fstat will return the current size.
// Can ignore return value. The only error that can happen is to tell you
// it was a NOP because the file is read only.
#if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(__MINGW64__) && !defined(_UCRT)
// Bug in VS2013 msvcrt. fflush on FILE open for READ changes file offset
// to 4096.
if (str->data.file->_flag & _IOWRT)
#endif
(void)fflush(str->data.file);
statret = fstat(fileno(str->data.file), &statbuf);
Expand Down