For 32-bit time_t (detected by _USE_32BIT_TIME_T), functions _fstat32(), _fstat() and fstat() are same. So fstat() can be defined as simple alias in def file.
Same applies for functions _fstat64i32(), _fstat() and fstat() when time_t is 64-bit. Simplify fstat() function, remove it from mingw-w64-crt/stdio/_fstat.c file and provide it via aliases in api-ms-win-crt-filesystem-l1-1-0.def.in and crt-aliases.def.in for all CRT import libraries. This fixes FIXME issue described in the fstat.c. This change also ensures that fstat and _fstat symbols would results in the same function calls. --- mingw-w64-crt/Makefile.am | 2 +- mingw-w64-crt/def-include/crt-aliases.def.in | 7 ++- .../api-ms-win-crt-filesystem-l1-1-0.def.in | 2 + mingw-w64-crt/stdio/_fstat.c | 52 ------------------- 4 files changed, 9 insertions(+), 54 deletions(-) delete mode 100644 mingw-w64-crt/stdio/_fstat.c diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am index 9eaf36d3ea3c..525f651d62e0 100644 --- a/mingw-w64-crt/Makefile.am +++ b/mingw-w64-crt/Makefile.am @@ -753,7 +753,7 @@ src_libmingwex=\ stdio/scanf2-argcount-char.c stdio/scanf2-argcount-wchar.c \ stdio/vfscanf2.S stdio/vfwscanf2.S stdio/vscanf2.S stdio/vsscanf2.S stdio/vswscanf2.S \ stdio/vwscanf2.S stdio/strtok_r.c stdio/scanf.S \ - stdio/_Exit.c stdio/_findfirst64i32.c stdio/_findnext64i32.c stdio/_fstat.c \ + stdio/_Exit.c stdio/_findfirst64i32.c stdio/_findnext64i32.c \ stdio/_ftime.c \ stdio/_stat.c stdio/_stat64i32.c stdio/_wfindfirst64i32.c stdio/_wfindnext64i32.c \ stdio/_wstat.c stdio/_wstat64i32.c stdio/asprintf.c stdio/fgetpos64.c \ diff --git a/mingw-w64-crt/def-include/crt-aliases.def.in b/mingw-w64-crt/def-include/crt-aliases.def.in index 33975d4911c9..62744a54ab54 100644 --- a/mingw-w64-crt/def-include/crt-aliases.def.in +++ b/mingw-w64-crt/def-include/crt-aliases.def.in @@ -56,7 +56,12 @@ ADD_UNDERSCORE(filelength) ADD_UNDERSCORE(fileno) ; ADD_UNDERSCORE(flushall) ADD_UNDERSCORE(fputchar) -; ADD_UNDERSCORE(fstat) +#ifdef FIXED_SIZE_SYMBOLS +ADD_UNDERSCORE(fstat) +#else +F32(fstat == _fstat32) +F64(fstat == _fstat64i32) +#endif ; ADD_UNDERSCORE(ftime) #if defined(UCRTBASE) ; _HUGE variable is not available in ucrtbase.dll and there is no replacement for it diff --git a/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def.in b/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def.in index 7396b3fb84f1..684baf712dcf 100644 --- a/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def.in +++ b/mingw-w64-crt/lib-common/api-ms-win-crt-filesystem-l1-1-0.def.in @@ -30,6 +30,8 @@ _findnext32 _findnext32i64 _findnext64 _findnext64i32 +F32(fstat == _fstat32) +F64(fstat == _fstat64i32) F32(_fstat == _fstat32) F64(_fstat == _fstat64i32) F32(_fstati64 == _fstat32i64) diff --git a/mingw-w64-crt/stdio/_fstat.c b/mingw-w64-crt/stdio/_fstat.c deleted file mode 100644 index efc097e2ce60..000000000000 --- a/mingw-w64-crt/stdio/_fstat.c +++ /dev/null @@ -1,52 +0,0 @@ -#define __CRT__NO_INLINE -#include <sys/stat.h> - -/* FIXME: Relying on _USE_32BIT_TIME_T, which is a user-macro, -during CRT compilation is plainly broken. Need an appropriate -implementation to provide users the ability of compiling the -CRT only with 32-bit time_t behavior. */ -#if defined(_USE_32BIT_TIME_T) -int __cdecl -fstat(int _Desc,struct stat *_Stat) -{ - struct _stat32 st; - int ret=_fstat32(_Desc,&st); - if (ret == -1) { - memset(_Stat,0,sizeof(struct stat)); - return -1; - } - /* struct stat and struct _stat32 - are the same for this case. */ - memcpy(_Stat, &st, sizeof(struct _stat32)); - return ret; -} -#else -int __cdecl -fstat(int _Desc,struct stat *_Stat) -{ - struct _stat64 st; - int ret=_fstat64(_Desc,&st); - if (ret == -1) { - memset(_Stat,0,sizeof(struct stat)); - return -1; - } - /* struct stat and struct _stat64i32 - are the same for this case. */ - _Stat->st_dev=st.st_dev; - _Stat->st_ino=st.st_ino; - _Stat->st_mode=st.st_mode; - _Stat->st_nlink=st.st_nlink; - _Stat->st_uid=st.st_uid; - _Stat->st_gid=st.st_gid; - _Stat->st_rdev=st.st_rdev; - _Stat->st_size=(_off_t) st.st_size; - _Stat->st_atime=st.st_atime; - _Stat->st_mtime=st.st_mtime; - _Stat->st_ctime=st.st_ctime; - return ret; -} -#endif - -/* Add __imp__fstat and __imp__stat symbols. */ -int (*__MINGW_IMP_SYMBOL(fstat))(int, struct stat *) = &fstat; - -- 2.20.1 _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public