crt: Fix fstat() to signal overflow and return correct type for directories
msvcrt _fstat function is broken and for directory fd it returns S_ISREG
type. 32-bit pre-msvcr110 _fstat does not properly signal size overflow.
UCRT seems to work correctly.
Add mingw-w64 fstat wrappers around msvcrt _fstat functions which change
S_IFMT to S_IFDIR if winapi filehandle has FILE_ATTRIBUTE_DIRECTORY
attribute set. Provide wrapper for all 4 fstat size_t/time_t variants.
For 32-bit pre-msvcr110 builds, adds similar workaround like for existing
mingw-w64 stat functions.
Currently our mingw-w64 header files defines non-underscore fstat and
fstat64 functions as __MINGW_ASM_CALL redirects to underscore _fstat32,
_fstat32i64, _fstat64i32, _fstat64 functions based on _FILE_OFFSET_BITS and
_TIME_BITS macros. So every one of these 4 functions needs its own fixup
wrapper. This change introduce 4 new non-underscore symbols fstat32,
fstat32i64, fstat64i32, fstat64 which provides necessary fixup and to which
mingw-w64 sys/stat.h header file redirects existing fstat and fstat64
functions. UCRT does not need any fixup, so new symbols are added as
aliases in def files.
Co-authored-by: LIU Hao <lh_mouse@126.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
24 files changed