On Tue, 23 Sep 2025, Pali Rohár wrote:

POSIX ftime() function returns int. MS _ftime() returns void. Add new
mingw-w64 wrappers around _ftime32() and _ftime64() which returns int 0
for implementing proper POSIX ftime() function.

Function ftime() defined in sys/timeb.h now redirects to either ftime32
or ftime64 symbol, which correctly returns an integer 0.
---
mingw-w64-crt/Makefile.am                    |  1 +
mingw-w64-crt/def-include/crt-aliases.def.in |  7 +------
mingw-w64-crt/misc/ftime32.c                 | 19 +++++++++++++++++++
mingw-w64-crt/misc/ftime64.c                 | 19 +++++++++++++++++++
mingw-w64-headers/crt/sys/timeb.h            |  4 ++--
5 files changed, 42 insertions(+), 8 deletions(-)
create mode 100644 mingw-w64-crt/misc/ftime32.c
create mode 100644 mingw-w64-crt/misc/ftime64.c

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index 57b110be331b..266eed840eac 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -1154,6 +1154,7 @@ src_libmingwex=\
  misc/mingw_setfp.c \
  misc/feupdateenv.c     misc/ftruncate.c           misc/fwide.c            
misc/getlogin.c              misc/getopt.c          \
  misc/gettimeofday.c    misc/__mingw_has_sse.c      \
+  misc/ftime32.c         misc/ftime64.c              \
  misc/mempcpy.c         misc/mingw-aligned-malloc.c \
  misc/mingw_matherr.c   misc/mingw_mbwc_convert.c  misc/mingw_usleep.c     
misc/mingw_wcstod.c          misc/mingw_wcstof.c    \
  misc/mingw_wcstold.c \
diff --git a/mingw-w64-crt/def-include/crt-aliases.def.in 
b/mingw-w64-crt/def-include/crt-aliases.def.in
index 42d1bfc1faa4..c568196b7265 100644
--- a/mingw-w64-crt/def-include/crt-aliases.def.in
+++ b/mingw-w64-crt/def-include/crt-aliases.def.in
@@ -72,12 +72,7 @@ ADD_UNDERSCORE(fstat)
F32(fstat == _fstat32)
F64(fstat == _fstat64i32)
#endif
-#ifdef FIXED_SIZE_SYMBOLS
-ADD_UNDERSCORE(ftime)
-#else
-F32(ftime == _ftime32)
-F64(ftime == _ftime64)
-#endif
+; ftime is provided in misc/ftime32.c or misc/ftime64.c as MS _ftime is not 
ABI compatible with POSIX ftime
#if defined(UCRTBASE)
; HUGE alias and _HUGE variable are provided by math/_huge.c
#elif defined(CRTDLL)
diff --git a/mingw-w64-crt/misc/ftime32.c b/mingw-w64-crt/misc/ftime32.c
new file mode 100644
index 000000000000..41cc31a6673c
--- /dev/null
+++ b/mingw-w64-crt/misc/ftime32.c
@@ -0,0 +1,19 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <sys/timeb.h>
+
+int __cdecl ftime32(struct __timeb32 *tb32);
+int __cdecl ftime32(struct __timeb32 *tb32)
+{
+    _ftime32(tb32);
+    return 0;
+}
+
+/* On 32-bit systems is ftime ABI using 32-bit time_t */
+#ifndef _WIN64
+int __attribute__ ((alias("ftime32"))) __cdecl ftime(struct timeb *);
+#endif
diff --git a/mingw-w64-crt/misc/ftime64.c b/mingw-w64-crt/misc/ftime64.c
new file mode 100644
index 000000000000..c30003b0302a
--- /dev/null
+++ b/mingw-w64-crt/misc/ftime64.c
@@ -0,0 +1,19 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+
+#include <sys/timeb.h>
+
+int __cdecl ftime64(struct __timeb64 *tb64);
+int __cdecl ftime64(struct __timeb64 *tb64)
+{
+    _ftime64(tb64);
+    return 0;
+}
+
+/* On 64-bit systems is ftime ABI using 64-bit time_t */
+#ifdef _WIN64
+int __attribute__ ((alias("ftime64"))) __cdecl ftime(struct timeb *);
+#endif
diff --git a/mingw-w64-headers/crt/sys/timeb.h 
b/mingw-w64-headers/crt/sys/timeb.h
index c35398539441..d52fd9c7f760 100644
--- a/mingw-w64-headers/crt/sys/timeb.h
+++ b/mingw-w64-headers/crt/sys/timeb.h
@@ -122,9 +122,9 @@ struct itimerspec {
#ifndef _CRTBLD
#if !defined (RC_INVOKED) && !defined (NO_OLDNAMES)
#ifndef _USE_32BIT_TIME_T
-  void __cdecl ftime (struct timeb *) __MINGW_ASM_CALL(_ftime64);
+  int __cdecl ftime (struct timeb *) __MINGW_ASM_CALL(ftime64);

Hmm, this seems a little bit odd, that we have double redirections in place here; we both have __MINGW_ASM_CALL(ftime64) in the headers, and we also have __attribute__ ((alias("ftime64"))) in the source files.

This doesn't seem to be a change in itself though, because earlier, we had similar redirections in the def file (ftime == _ftime64).

But normally I think we'd make do with either of the redirection mechanisms, not have both of them (as it becomes a bit surprising for future maintainance that the same thing has to be changed in two places).

Normally it should be enough to have the __MINGW_ASM_CALL in the headers, right? Unless we need to cope with users who call it without including headers (or declare it themselves). Is that the case here?

// Martin

_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to