From 2c604863de53cf062718debb6c0aae8044a049b0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 6 Oct 2019 00:13:26 +0200 Subject: [PATCH] Fix compilation after fpos_t change in with MinGW runtime 5.2 fpos_t is now a union and not just a simple typedef any more, so we can't cast between it and long long. Unfortunately we still need to convert between the two, so add an explicit version check and use the private union field to make this work with the latest MinGW 32 versions. --- include/wx/filefn.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/include/wx/filefn.h b/include/wx/filefn.h index b3ee95fa91..4d25bf13e1 100644 --- a/include/wx/filefn.h +++ b/include/wx/filefn.h @@ -162,7 +162,21 @@ enum wxPosixPermissions inline long long wxFtell(FILE* fp) { fpos_t pos; - return fgetpos(fp, &pos) == 0 ? pos : static_cast(-1LL); + if ( fgetpos(fp, &pos) != 0 ) + return -1LL; + + // Unfortunately our interface assumes that the file position + // is representable as "long long", so we have to get it from + // fpos_t, even though it's an opaque type. And its exact + // representation has changed in MinGW, so we have to test for + // mingwrt version. + #if wxCHECK_MINGW32_VERSION(5, 2) + // In 5.2.2 it's a union with a __value field. + return pos.__value; + #else + // Up to 5.1.1 it was a simple typedef. + return pos; + #endif } #else #define wxFtell ftello64