Skip to content

Commit

Permalink
Fixing support for mingw toolchains that target the newer ucrt (Khron…
Browse files Browse the repository at this point in the history
  • Loading branch information
Honeybunch authored Oct 25, 2022
1 parent 7f051ad commit cdb12cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
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

0 comments on commit cdb12cc

Please sign in to comment.