crt: Fix overflow detection in mingw-w64 fgetpos() emulation Recent Windows versions have different behavior of 32-bit fgetpos and returns -1 with errno set to EINVAL when position does not fit into 32 bits. So check for EINVAL and convert it to EOVERFLOW. This fixes t_fseeki64.c test when compiled against msvcrt20.dll and run on Windows 10 against the system os version of msvcrt20.dll.
diff --git a/mingw-w64-crt/stdio/fgetpos.c b/mingw-w64-crt/stdio/fgetpos.c index aa3feda..8c93dea 100644 --- a/mingw-w64-crt/stdio/fgetpos.c +++ b/mingw-w64-crt/stdio/fgetpos.c
@@ -26,7 +26,10 @@ * then fgetpos32() returns -1, sets pos32 to -1 and do not change errno. * Non-zero value in [63:32] bits of 64-bit position offset does not trigger * any error condition. In other error cases fgetpos32() returns -1, - * sets pos32 to -1 and errno to error value. */ + * sets pos32 to -1 and errno to error value. + * Recent Windows versions have different behavior and returns -1 with errno + * set to EINVAL when position does not fit into 32 bits. + */ errno = 0; ret = fgetpos32(_File, &pos32); @@ -34,6 +37,8 @@ { if (errno == 0) /* This detects overflow when [31] bit is set. */ errno = EOVERFLOW; + else if (errno == EINVAL) /* Value does not fit into 32 bits. */ + errno = EOVERFLOW; *_Pos = pos32; return ret; }