Move LFS defines of stat64/fstat64 from _mingw_stat64.h to sys/stat.h. Move struct stat from _mingw_stat64.h to sys/stat.h.
Fix definition of POSIX struct stat to follow both _FILE_OFFSET_BITS and _USE_32BIT_TIME_T settings. Fix declaration of POSIX stat(), fstat() and mingw-w64 wstat() functions to follow all combinations of _FILE_OFFSET_BITS and _USE_32BIT_TIME_T settings. Declare fstat() as a function instead of macro. Define it as alias via __MINGW_ASM_CALL to one of the CRT _fstat* function based on _FILE_OFFSET_BITS and _USE_32BIT_TIME_T settings. In the same way declare stat() and wstat() as functions. But as alias to one of the mingw-w64 (w)stat* function. This is needed because msvcrt _(w)stat* functions have issue with trailing slash and requires mingw-w64 wrapper for POSIX compatibility. Additionaly define struct stat64 for LFS functions stat64(), fstat64() and mingw-w64 function wstat64(). And again declare them as a functions instead of macro. stat has to be declared as a function, not as a macro because it would override effect of struct stat. --- mingw-w64-crt/misc/crtdll_fstat.c | 1 + mingw-w64-crt/misc/crtdll_stat.c | 1 + mingw-w64-crt/stdio/_fstat64.c | 5 +- mingw-w64-crt/stdio/stat64.c | 8 ++- mingw-w64-crt/stdio/wstat64.c | 7 ++- mingw-w64-headers/crt/_mingw_stat64.h | 23 ++------- mingw-w64-headers/crt/sys/stat.h | 74 +++++++++++++++++++-------- 7 files changed, 66 insertions(+), 53 deletions(-) diff --git a/mingw-w64-crt/misc/crtdll_fstat.c b/mingw-w64-crt/misc/crtdll_fstat.c index f0b3b748b0eb..cf51ffb6a760 100644 --- a/mingw-w64-crt/misc/crtdll_fstat.c +++ b/mingw-w64-crt/misc/crtdll_fstat.c @@ -4,6 +4,7 @@ * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ +#define __CRT__NO_INLINE #include <sys/stat.h> #include "crtdll_stat.h" diff --git a/mingw-w64-crt/misc/crtdll_stat.c b/mingw-w64-crt/misc/crtdll_stat.c index f17bfbe93488..944596556f44 100644 --- a/mingw-w64-crt/misc/crtdll_stat.c +++ b/mingw-w64-crt/misc/crtdll_stat.c @@ -4,6 +4,7 @@ * No warranty is given; refer to the file DISCLAIMER.PD within this package. */ +#define __CRT__NO_INLINE #include <sys/stat.h> #include "crtdll_stat.h" diff --git a/mingw-w64-crt/stdio/_fstat64.c b/mingw-w64-crt/stdio/_fstat64.c index 0c059499b7e7..b8032ef7ace3 100644 --- a/mingw-w64-crt/stdio/_fstat64.c +++ b/mingw-w64-crt/stdio/_fstat64.c @@ -45,6 +45,5 @@ static int __cdecl emu__fstat64(int fd, struct _stat64 *stat) #define CALL fd, stat #include "msvcrt_or_emu_glue.h" -#undef fstat64 -int __attribute__ ((alias ("_fstat64"))) __cdecl fstat64(int, struct _stat64 *); -extern int __attribute__ ((alias (__MINGW64_STRINGIFY(__MINGW_IMP_SYMBOL(_fstat64))))) (__cdecl *__MINGW_IMP_SYMBOL(fstat64))(int, struct _stat64 *); +int __attribute__ ((alias ("_fstat64"))) __cdecl fstat64(int, struct stat64 *); +extern int __attribute__ ((alias (__MINGW64_STRINGIFY(__MINGW_IMP_SYMBOL(_fstat64))))) (__cdecl *__MINGW_IMP_SYMBOL(fstat64))(int, struct stat64 *); diff --git a/mingw-w64-crt/stdio/stat64.c b/mingw-w64-crt/stdio/stat64.c index 2e1d66ebc3fd..096bae132d35 100644 --- a/mingw-w64-crt/stdio/stat64.c +++ b/mingw-w64-crt/stdio/stat64.c @@ -10,14 +10,12 @@ char *__mingw_fix_stat_path(const char *_path); -#undef stat64 -int __cdecl stat64(const char *_Filename, struct _stat64 *_Stat); -int __cdecl stat64(const char *_Filename, struct _stat64 *_Stat) +int __cdecl stat64(const char *_Filename, struct stat64 *_Stat) { char *_path = __mingw_fix_stat_path(_Filename); - int ret = _stat64(_path, _Stat); + int ret = _stat64(_path, (struct _stat64 *)_Stat); if (_path != _Filename) free(_path); return ret; } -int (__cdecl *__MINGW_IMP_SYMBOL(stat64))(const char *, struct _stat64 *) = stat64; +int (__cdecl *__MINGW_IMP_SYMBOL(stat64))(const char *, struct stat64 *) = stat64; diff --git a/mingw-w64-crt/stdio/wstat64.c b/mingw-w64-crt/stdio/wstat64.c index a24d81cd244e..399efcf72c3b 100644 --- a/mingw-w64-crt/stdio/wstat64.c +++ b/mingw-w64-crt/stdio/wstat64.c @@ -10,13 +10,12 @@ wchar_t *__mingw_fix_wstat_path(const wchar_t *_path); -int __cdecl wstat64(const wchar_t *_Filename, struct _stat64 *_Stat); -int __cdecl wstat64(const wchar_t *_Filename, struct _stat64 *_Stat) +int __cdecl wstat64(const wchar_t *_Filename, struct stat64 *_Stat) { wchar_t *_path = __mingw_fix_wstat_path(_Filename); - int ret = _wstat64(_path, _Stat); + int ret = _wstat64(_path, (struct _stat64 *)_Stat); if (_path != _Filename) free(_path); return ret; } -int (__cdecl *__MINGW_IMP_SYMBOL(wstat64))(const wchar_t *, struct _stat64 *) = wstat64; +int (__cdecl *__MINGW_IMP_SYMBOL(wstat64))(const wchar_t *, struct stat64 *) = wstat64; diff --git a/mingw-w64-headers/crt/_mingw_stat64.h b/mingw-w64-headers/crt/_mingw_stat64.h index 8ce097561116..84eabba9698b 100644 --- a/mingw-w64-headers/crt/_mingw_stat64.h +++ b/mingw-w64-headers/crt/_mingw_stat64.h @@ -1,5 +1,8 @@ #ifndef _STAT_DEFINED +/* __stat64 is needed for compatibility with msvc */ +#define __stat64 _stat64 + #ifdef _USE_32BIT_TIME_T #define _fstat _fstat32 #define _fstati64 _fstat32i64 @@ -30,22 +33,6 @@ __time32_t st_ctime; }; -#ifndef NO_OLDNAMES - struct stat { - _dev_t st_dev; - _ino_t st_ino; - unsigned short st_mode; - short st_nlink; - short st_uid; - short st_gid; - _dev_t st_rdev; - _off_t st_size; - time_t st_atime; - time_t st_mtime; - time_t st_ctime; - }; -#endif /* NO_OLDNAMES */ - struct _stat32i64 { _dev_t st_dev; _ino_t st_ino; @@ -88,9 +75,5 @@ __time64_t st_ctime; }; -#define __stat64 _stat64 -#define stat64 _stat64 /* for POSIX */ -#define fstat64 _fstat64 /* for POSIX */ - #define _STAT_DEFINED #endif /* _STAT_DEFINED */ diff --git a/mingw-w64-headers/crt/sys/stat.h b/mingw-w64-headers/crt/sys/stat.h index b972a0af4444..b7884d89fae4 100644 --- a/mingw-w64-headers/crt/sys/stat.h +++ b/mingw-w64-headers/crt/sys/stat.h @@ -124,31 +124,63 @@ extern "C" { #endif -#if !defined (RC_INVOKED) && !defined (NO_OLDNAMES) -int __cdecl fstat(int _Desc,struct stat *_Stat); -#ifdef _UCRT - __mingw_ovr int __cdecl stat(const char *_Filename,struct stat *_Stat) - { - return _stat(_Filename, (struct _stat *)_Stat); - } - __mingw_ovr int __cdecl wstat(const wchar_t *_Filename,struct stat *_Stat) - { - return _wstat(_Filename, (struct _stat *)_Stat); - } -#else -int __cdecl stat(const char *_Filename,struct stat *_Stat); -int __cdecl wstat(const wchar_t *_Filename,struct stat *_Stat); -#endif -#endif /* !RC_INVOKED && !NO_OLDNAMES */ - +#if !defined(NO_OLDNAMES) || defined(_POSIX) + +struct stat { + _dev_t st_dev; + _ino_t st_ino; + unsigned short st_mode; + short st_nlink; + short st_uid; + short st_gid; + _dev_t st_rdev; + off_t st_size; /* off_t follows _FILE_OFFSET_BITS */ + time_t st_atime; /* time_t follows _USE_32BIT_TIME_T */ + time_t st_mtime; + time_t st_ctime; +}; + +#ifndef __CRT__NO_INLINE #if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64) #ifdef _USE_32BIT_TIME_T -#define stat _stat32i64 -#define fstat _fstat32i64 +int __cdecl fstat(int _Desc, struct stat *_Stat) __MINGW_ASM_CALL(_fstat32i64); +int __cdecl stat(const char *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(stat32i64); +int __cdecl wstat(const wchar_t *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(wstat32i64); #else -#define stat _stat64 -#define fstat _fstat64 +int __cdecl fstat(int _Desc, struct stat *_Stat) __MINGW_ASM_CALL(_fstat64); +int __cdecl stat(const char *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(stat64); +int __cdecl wstat(const wchar_t *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(wstat64); #endif +#else +#ifdef _USE_32BIT_TIME_T +int __cdecl fstat(int _Desc, struct stat *_Stat) __MINGW_ASM_CALL(_fstat32); +int __cdecl stat(const char *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(stat32); +int __cdecl wstat(const wchar_t *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(wstat32); +#else +int __cdecl fstat(int _Desc, struct stat *_Stat) __MINGW_ASM_CALL(_fstat64i32); +int __cdecl stat(const char *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(stat64i32); +int __cdecl wstat(const wchar_t *_Filename, struct stat *_Stat) __MINGW_ASM_CALL(wstat64i32); +#endif +#endif +#endif + +struct stat64 { + _dev_t st_dev; + _ino_t st_ino; + unsigned short st_mode; + short st_nlink; + short st_uid; + short st_gid; + _dev_t st_rdev; + __MINGW_EXTENSION __int64 st_size; + __time64_t st_atime; + __time64_t st_mtime; + __time64_t st_ctime; +}; +int __cdecl fstat64(int _Desc, struct stat64 *_Stat); +int __cdecl stat64(const char *_Filename, struct stat64 *_Stat); +int __cdecl wstat64(const wchar_t *_Filename, struct stat64 *_Stat); + #endif #ifdef __cplusplus -- 2.20.1 _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public