Hi,

There have been discussions about adding support for _FILE_BITS and _TIME_BITS 
macros in mingw-w64 header files.

Some of functions provided by winpthreads library use `struct timespec` which 
depends on `time_t`, however winpthreads does not handle _USE_32BIT_TIME_t and 
_TIME_BITS macros.

This patch series adds handling of these macros to winpthreads. It also 
includes some patches that I had in mind for quite some time.

0001.txt:

Currently none of winpthreads' source files includes `config.h` which makes all 
check performed in `configure` useless.
This patch removes existing checks, but preserve structure and comments so 
future patches can add more checks.

0002.txt:

This patch makes `make dist` work.

The `libwinpthread_la_SOURCES` lists some header files which are no longer 
present in the source tree.

This patch also explicitly adds `build-aux/windres-rc` to EXTRA_DIST. This file 
is required for MSVC builds.

0003.txt:

This patch removes declaration of three internal functions from `pthread.h`. 
These functions are also declared in internal `misc.h`, so I see no reason to 
have them in `pthread.h`.

(Some of these functions are modified in 0004.txt).

0004.txt:

This patch adds handling of _USE_32BIT_TIME_T and _TIME_BITS. See commit 
message for some details (to not repeat them here).

The existing functions are redefined as static and explicitly use `struct 
_timespec64`. The 32- and 64-suffiex external functions are wrappers around 
them. Some internal functions are also changed to use `struct _timespec64`.

I would like to point out the following details.

I would prefer using a .def file to export 64-suffixed and plain version 
without the suffix, but unfortunately libtool mishandles flags like `-Wl` with 
MSVC-like tools. For example, to pass `-def:file.def` to the linker we need to 
write ugly workaround like `-Wl,-Xlinker,-def:file.def`.

If this ugly workaround is OK, I can add a .def file instead.

I also added `AC_CHECK_SIZEOF(time_t)` in `configure.ac` to choose whether 
exported plain versions use 32- or 64-suffixed version.

I also included `config.h` (since it is used now) from all source files in 
`src` subdirectory.

0005.txt:

The `pthread_setname_np` function defined in thread.c uses `mbstowcs` which is 
not thread-safe. Use `mbsrtowcs` instead.

0006.txt:

This patch adds a couple of MSVC-related changes to the build system.

Check for `_MSC_VER` instead of checking `$CC` to recognize MSVC-like 
compilers. Both `cl.exe` and `clang-cl.exe` define _MSC_VER. Any better 
suggestions are welcome.

Use `-W3` instead of `-Wall` when using MSVC-like compilers.  `-Wall` is too 
noisy.

I also added `-D_CRT_DECLARE_NONSTDC_NAMES` which allows to use MSVC's 
`-Zc:__STDC__` options. (See 
https://learn.microsoft.com/en-us/cpp/build/reference/zc-stdc).

Other notes:

Makefile.am currently unconditionally defines `WINPTHREAD_DBG=1`, maybe it 
would make sense to add an option which will control whether this macro is 
defined?

I would like to move definition of `WIN32_LEAN_AND_MEAN` from Makefile.am to 
source files (just before `#include <windows.h>`.

- Kirill Makurin
From f85cac55917dd8ec05ff0dbbbe910f41eb5b6512 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Tue, 15 Apr 2025 03:31:25 +0900
Subject: [PATCH 1/6] winpthreads: remove unused checks from configure.ac

Currently no source files include config.h, which means that
results of all tests from configure.ac are unused.

Most of the checks were testing for presence of features which are
now available with both mingw-w64 and MSVC.

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 mingw-w64-libraries/winpthreads/configure.ac | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/configure.ac 
b/mingw-w64-libraries/winpthreads/configure.ac
index 0ae6f027c..503a1d8e1 100644
--- a/mingw-w64-libraries/winpthreads/configure.ac
+++ b/mingw-w64-libraries/winpthreads/configure.ac
@@ -35,21 +35,12 @@ LT_INIT([win32-dll])
 LT_LANG([Windows Resource])
 
 # Checks for libraries.
-# FIXME: Replace `main' with a function in `-lpthread':
-#AC_CHECK_LIB([pthread], [main])
 
 # Checks for header files.
-AC_CHECK_HEADERS([limits.h sys/timeb.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
-AC_C_INLINE
-AC_TYPE_SIZE_T
 
 # Checks for library functions.
-#AC_FUNC_MALLOC
-#AC_FUNC_REALLOC
-# mingw-w64 should already have them
-#AC_CHECK_FUNCS([ftime gettimeofday memset])
 
 AC_CONFIG_FILES([Makefile tests/Makefile])
 AC_OUTPUT
-- 
2.46.1.windows.1

From daf562d9f4623009803a5effc1fc52a87473b618 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Tue, 15 Apr 2025 04:23:34 +0900
Subject: [PATCH 2/6] winpthreads: fix `make dist`

libwinpthread_la_SOURCES lists header files which are no longer present
in the source tree. This causes `make dist` to fail.

Explicitly add `build-aux/windres-rc` to EXTRA_DIST.

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 mingw-w64-libraries/winpthreads/Makefile.am | 25 +++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/Makefile.am 
b/mingw-w64-libraries/winpthreads/Makefile.am
index 6b0338af0..5db1636fe 100644
--- a/mingw-w64-libraries/winpthreads/Makefile.am
+++ b/mingw-w64-libraries/winpthreads/Makefile.am
@@ -9,10 +9,23 @@ lib_LTLIBRARIES = libwinpthread.la
 include_HEADERS = include/pthread.h include/sched.h include/semaphore.h 
include/pthread_unistd.h include/pthread_time.h include/pthread_compat.h 
include/pthread_signal.h
 libwinpthread_la_CPPFLAGS = -I$(srcdir)/include -DIN_WINPTHREAD 
-DWINPTHREAD_DBG=1
 libwinpthread_la_LDFLAGS = -no-undefined -version-info 1:0:0
-libwinpthread_la_SOURCES = \
-  src/barrier.h  src/cond.h  src/misc.h  src/mutex.h  src/rwlock.h  
src/spinlock.h  src/thread.h  src/ref.h  src/sem.h  src/wpth_ver.h \
-  src/barrier.c  src/cond.c  src/misc.c  src/mutex.c  src/rwlock.c  
src/spinlock.c  src/thread.c  src/ref.c  src/sem.c  src/sched.c \
-  src/winpthread_internal.h  src/clock.c src/nanosleep.c src/version.rc
+
+libwinpthread_la_SOURCES =     \
+  src/barrier.h src/barrier.c  \
+  src/cond.h    src/cond.c     \
+  src/misc.h    src/misc.c     \
+                src/mutex.c    \
+  src/ref.h     src/ref.c      \
+  src/rwlock.h  src/rwlock.c   \
+  src/sem.h     src/sem.c      \
+                src/spinlock.c \
+                src/sched.c    \
+  src/thread.h  src/thread.c   \
+  src/clock.c                  \
+  src/nanosleep.c              \
+  src/winpthread_internal.h    \
+  src/wpth_ver.h               \
+  src/version.rc
 
 if MSVC
 AM_CFLAGS += -nologo
@@ -29,6 +42,10 @@ fakelib_libgcc_s_a_SOURCES =
 fakelib_libgcc_eh_a_SOURCES =
 endif
 
+# Extra files to add into archive with `make dist`
+EXTRA_DIST = \
+  build-aux/windres-rc
+
 # Tell libtool how to use the resource compiler
 .rc.lo:
        $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --tag=RC --mode=compile 
$(RC) $(RCFLAGS) -i $< -o $@
-- 
2.46.1.windows.1

From 71c1f2934130ef8c06e0d05a85551bab38e91e43 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Tue, 15 Apr 2025 04:44:23 +0900
Subject: [PATCH 3/6] winpthreads: remove some internal functions from
 pthread.h

Declarations of the following functions have been removed from pthread.h:

  - _pthread_time_in_ms
  - _pthread_time_in_ms_from_timespec
  - _pthread_rel_time_in_ms

These functions are declared in internal misc.h.

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 mingw-w64-libraries/winpthreads/include/pthread.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h 
b/mingw-w64-libraries/winpthreads/include/pthread.h
index 4a5822427..3a553c020 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread.h
@@ -357,9 +357,6 @@ WINPTHREAD_API struct _pthread_cleanup ** pthread_getclean 
(void);
 WINPTHREAD_API void * pthread_gethandle (pthread_t t);
 WINPTHREAD_API void * pthread_getevent (void);
 
-WINPTHREAD_API unsigned long long _pthread_rel_time_in_ms(const struct 
timespec *ts);
-WINPTHREAD_API unsigned long long _pthread_time_in_ms(void);
-WINPTHREAD_API unsigned long long _pthread_time_in_ms_from_timespec(const 
struct timespec *ts);
 WINPTHREAD_API int _pthread_tryjoin (pthread_t t, void **res);
 WINPTHREAD_API int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a);
 WINPTHREAD_API int pthread_rwlockattr_getpshared(pthread_rwlockattr_t *a, int 
*s);
-- 
2.46.1.windows.1

From eb6cad751b24fe5fd666d2bf59772ceda298210a Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Tue, 15 Apr 2025 09:02:23 +0900
Subject: [PATCH 4/6] winpthreads: handle _USE_32BIT_TIME_T and _TIME_BITS

This patch adds handling for CRT's _USE_32BIT_TIME_T and
POSIX _TIME_BITS macros.

This patch adds two versions of each public function which uses
`struct timespec`. One version with suffix `32`, which uses
`struct _timespec32` and one version with suffix `64`, which uses
`struct _timespec64`.

The plain versions without the suffix are implemented as static inline functions
which call explicitly sized version and perform type cast from
`struct timespec*` to explicitly sized version of the structure.

External symbols for plain versions are still provided. They use either 32- or
64-suffixed versions, as determined during configuration.

Other changes:

New macro `WINPTHREADS_ALWAYS_INLINE` has been added to `pthread_compat.h`.
This macro is used by static inline function described above.

Add `AC_CHECK_SIZEOF(time_t)` to configure.ac.

config.h is now included from each source file in `src` subdirectory.

Function `__pthread_clock_nanosleep` has been removed.
winpthreads now provides `clock_nanosleep` with standard POSIX name.

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 mingw-w64-libraries/winpthreads/configure.ac  |   1 +
 .../winpthreads/include/pthread.h             |  66 ++++++-
 .../winpthreads/include/pthread_compat.h      |   2 +
 .../winpthreads/include/pthread_time.h        |  68 ++++++++
 .../winpthreads/include/semaphore.h           |  12 ++
 mingw-w64-libraries/winpthreads/src/barrier.c |  14 +-
 mingw-w64-libraries/winpthreads/src/clock.c   | 164 ++++++++++++++++--
 mingw-w64-libraries/winpthreads/src/cond.c    |  94 +++++-----
 mingw-w64-libraries/winpthreads/src/misc.c    |   8 +-
 mingw-w64-libraries/winpthreads/src/misc.h    |   4 +-
 mingw-w64-libraries/winpthreads/src/mutex.c   |  36 +++-
 .../winpthreads/src/nanosleep.c               |  51 +++++-
 mingw-w64-libraries/winpthreads/src/rwlock.c  |  88 ++++++++--
 mingw-w64-libraries/winpthreads/src/sched.c   |   4 +
 mingw-w64-libraries/winpthreads/src/sem.c     |  34 +++-
 mingw-w64-libraries/winpthreads/src/thread.c  |  44 ++++-
 16 files changed, 594 insertions(+), 96 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/configure.ac 
b/mingw-w64-libraries/winpthreads/configure.ac
index 503a1d8e1..fa882495f 100644
--- a/mingw-w64-libraries/winpthreads/configure.ac
+++ b/mingw-w64-libraries/winpthreads/configure.ac
@@ -39,6 +39,7 @@ LT_LANG([Windows Resource])
 # Checks for header files.
 
 # Checks for typedefs, structures, and compiler characteristics.
+AC_CHECK_SIZEOF([time_t], [], [#include <time.h>])
 
 # Checks for library functions.
 
diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h 
b/mingw-w64-libraries/winpthreads/include/pthread.h
index 3a553c020..d42eeff05 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread.h
@@ -274,9 +274,35 @@ WINPTHREAD_API int       pthread_getname_np(pthread_t 
thread, char *name, size_t
 
 WINPTHREAD_API int pthread_rwlock_init(pthread_rwlock_t *rwlock_, const 
pthread_rwlockattr_t *attr);
 WINPTHREAD_API int pthread_rwlock_wrlock(pthread_rwlock_t *l);
+WINPTHREAD_API int pthread_rwlock_timedwrlock32(pthread_rwlock_t *rwlock, 
const struct _timespec32 *ts);
+WINPTHREAD_API int pthread_rwlock_timedwrlock64(pthread_rwlock_t *rwlock, 
const struct _timespec64 *ts);
+#ifdef IN_WINPTHREAD
 WINPTHREAD_API int pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const 
struct timespec *ts);
+#else
+static WINPTHREADS_ALWAYS_INLINE int 
pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock, const struct timespec *ts)
+{
+#if defined(_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32)
+  return pthread_rwlock_timedwrlock32 (rwlock, (const struct _timespec32*) ts);
+#else
+  return pthread_rwlock_timedwrlock64 (rwlock, (const struct _timespec64*) ts);
+#endif
+}
+#endif
 WINPTHREAD_API int pthread_rwlock_rdlock(pthread_rwlock_t *l);
+WINPTHREAD_API int pthread_rwlock_timedrdlock32(pthread_rwlock_t *l, const 
struct _timespec32 *ts);
+WINPTHREAD_API int pthread_rwlock_timedrdlock64(pthread_rwlock_t *l, const 
struct _timespec64 *ts);
+#ifdef IN_WINPTHREAD
 WINPTHREAD_API int pthread_rwlock_timedrdlock(pthread_rwlock_t *l, const 
struct timespec *ts);
+#else
+static WINPTHREADS_ALWAYS_INLINE int 
pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock, const struct timespec *ts)
+{
+#if defined(_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32)
+  return pthread_rwlock_timedrdlock32 (rwlock, (const struct _timespec32*) ts);
+#else
+  return pthread_rwlock_timedrdlock64 (rwlock, (const struct _timespec64*) ts);
+#endif
+}
+#endif
 WINPTHREAD_API int pthread_rwlock_unlock(pthread_rwlock_t *l);
 WINPTHREAD_API int pthread_rwlock_tryrdlock(pthread_rwlock_t *l);
 WINPTHREAD_API int pthread_rwlock_trywrlock(pthread_rwlock_t *l);
@@ -287,11 +313,50 @@ WINPTHREAD_API int pthread_cond_destroy(pthread_cond_t 
*cv);
 WINPTHREAD_API int pthread_cond_signal (pthread_cond_t *cv);
 WINPTHREAD_API int pthread_cond_broadcast (pthread_cond_t *cv);
 WINPTHREAD_API int pthread_cond_wait (pthread_cond_t *cv, pthread_mutex_t 
*external_mutex);
+WINPTHREAD_API int pthread_cond_timedwait32(pthread_cond_t *cv, 
pthread_mutex_t *external_mutex, const struct _timespec32 *t);
+WINPTHREAD_API int pthread_cond_timedwait64(pthread_cond_t *cv, 
pthread_mutex_t *external_mutex, const struct _timespec64 *t);
+#ifdef IN_WINPTHREAD
 WINPTHREAD_API int pthread_cond_timedwait(pthread_cond_t *cv, pthread_mutex_t 
*external_mutex, const struct timespec *t);
+#else
+static WINPTHREADS_ALWAYS_INLINE int pthread_cond_timedwait(pthread_cond_t 
*cv, pthread_mutex_t *external_mutex, const struct timespec *t)
+{
+#if defined(_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32)
+  return pthread_cond_timedwait32 (cv, external_mutex, (const struct 
_timespec32*) t);
+#else
+  return pthread_cond_timedwait64 (cv, external_mutex, (const struct 
_timespec64*) t);
+#endif
+}
+#endif
+WINPTHREAD_API int pthread_cond_timedwait32_relative_np(pthread_cond_t *cv, 
pthread_mutex_t *external_mutex, const struct _timespec32 *t);
+WINPTHREAD_API int pthread_cond_timedwait64_relative_np(pthread_cond_t *cv, 
pthread_mutex_t *external_mutex, const struct _timespec64 *t);
+#ifdef IN_WINPTHREAD
 WINPTHREAD_API int pthread_cond_timedwait_relative_np(pthread_cond_t *cv, 
pthread_mutex_t *external_mutex, const struct timespec *t);
+#else
+static WINPTHREADS_ALWAYS_INLINE int 
pthread_cond_timedwait_relative_np(pthread_cond_t *cv, pthread_mutex_t 
*external_mutex, const struct timespec *t)
+{
+#if defined(_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32)
+  return pthread_cond_timedwait32_relative_np (cv, external_mutex, (const 
struct _timespec32*) t);
+#else
+  return pthread_cond_timedwait64_relative_np (cv, external_mutex, (const 
struct _timespec64*) t);
+#endif
+}
+#endif
 
 WINPTHREAD_API int pthread_mutex_lock(pthread_mutex_t *m);
+WINPTHREAD_API int pthread_mutex_timedlock32(pthread_mutex_t *m, const struct 
_timespec32 *ts);
+WINPTHREAD_API int pthread_mutex_timedlock64(pthread_mutex_t *m, const struct 
_timespec64 *ts);
+#ifdef IN_WINPTHREAD
 WINPTHREAD_API int pthread_mutex_timedlock(pthread_mutex_t *m, const struct 
timespec *ts);
+#else
+static WINPTHREADS_ALWAYS_INLINE int pthread_mutex_timedlock(pthread_mutex_t 
*m, const struct timespec *ts)
+{
+#if defined(_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32)
+        return pthread_mutex_timedlock32 (m, (const struct _timespec32*) ts);
+#else
+        return pthread_mutex_timedlock64 (m, (const struct _timespec64*) ts);
+#endif
+}
+#endif
 WINPTHREAD_API int pthread_mutex_unlock(pthread_mutex_t *m);
 WINPTHREAD_API int pthread_mutex_trylock(pthread_mutex_t *m);
 WINPTHREAD_API int pthread_mutex_init(pthread_mutex_t *m, const 
pthread_mutexattr_t *a);
@@ -345,7 +410,6 @@ WINPTHREAD_API int pthread_condattr_getclock (const 
pthread_condattr_t *attr,
        clockid_t *clock_id);
 WINPTHREAD_API int pthread_condattr_setclock(pthread_condattr_t *attr,
        clockid_t clock_id);
-WINPTHREAD_API int __pthread_clock_nanosleep(clockid_t clock_id, int flags, 
const struct timespec *rqtp, struct timespec *rmtp);
 
 WINPTHREAD_API int pthread_barrierattr_init(void **attr);
 WINPTHREAD_API int pthread_barrierattr_destroy(void **attr);
diff --git a/mingw-w64-libraries/winpthreads/include/pthread_compat.h 
b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
index 96118722d..a0895a0ee 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread_compat.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread_compat.h
@@ -98,6 +98,7 @@ typedef unsigned short mode_t;
 #ifdef __GNUC__
 
 #define WINPTHREADS_INLINE inline
+#define WINPTHREADS_ALWAYS_INLINE inline __attribute__((__always_inline__))
 #define WINPTHREADS_ATTRIBUTE(X) __attribute__(X)
 #define WINPTHREADS_SECTION(X) __section__(X)
 
@@ -110,6 +111,7 @@ typedef int     pid_t;
 #endif
 
 #define WINPTHREADS_INLINE __inline
+#define WINPTHREADS_ALWAYS_INLINE __inline __forceinline
 #define WINPTHREADS_ATTRIBUTE(X) __declspec X
 #define WINPTHREADS_SECTION(X) allocate(X)
 
diff --git a/mingw-w64-libraries/winpthreads/include/pthread_time.h 
b/mingw-w64-libraries/winpthreads/include/pthread_time.h
index 363154d67..d49b3850d 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread_time.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread_time.h
@@ -73,12 +73,80 @@
 extern "C" {
 #endif
 
+WINPTHREAD_API int __cdecl nanosleep32(const struct _timespec32 *request, 
struct _timespec32 *remain);
+WINPTHREAD_API int __cdecl nanosleep64(const struct _timespec64 *request, 
struct _timespec64 *remain);
+#ifdef IN_WINPTHREAD
 WINPTHREAD_API int __cdecl nanosleep(const struct timespec *request, struct 
timespec *remain);
+#else
+static WINPTHREADS_ALWAYS_INLINE int __cdecl nanosleep(const struct timespec 
*request, struct timespec *remain)
+{
+#if defined(_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32)
+  return nanosleep32((const struct _timespec32*) request, (struct 
_timespec32*) remain);
+#else
+  return nanosleep64((const struct _timespec64*) request, (struct 
_timespec64*) remain);
+#endif
+}
+#endif
 
+WINPTHREAD_API int __cdecl clock_nanosleep32(clockid_t clock_id, int flags, 
const struct _timespec32 *request, struct _timespec32 *remain);
+WINPTHREAD_API int __cdecl clock_nanosleep64(clockid_t clock_id, int flags, 
const struct _timespec64 *request, struct _timespec64 *remain);
+#ifdef IN_WINPTHREAD
 WINPTHREAD_API int __cdecl clock_nanosleep(clockid_t clock_id, int flags, 
const struct timespec *request, struct timespec *remain);
+#else
+static WINPTHREADS_ALWAYS_INLINE int __cdecl clock_nanosleep(clockid_t 
clock_id, int flags, const struct timespec *request, struct timespec *remain)
+{
+#if defined(_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32)
+  return clock_nanosleep32(clock_id, flags, (const struct _timespec32*) 
request, (struct _timespec32*) remain);
+#else
+  return clock_nanosleep64(clock_id, flags, (const struct _timespec64*) 
request, (struct _timespec64*) remain);
+#endif
+}
+#endif
+
+WINPTHREAD_API int __cdecl clock_getres32(clockid_t clock_id, struct 
_timespec32 *res);
+WINPTHREAD_API int __cdecl clock_getres64(clockid_t clock_id, struct 
_timespec64 *res);
+#ifdef IN_WINPTHREAD
 WINPTHREAD_API int __cdecl clock_getres(clockid_t clock_id, struct timespec 
*res);
+#else
+static WINPTHREADS_ALWAYS_INLINE int __cdecl clock_getres(clockid_t clock_id, 
struct timespec *res)
+{
+#if defined(_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32)
+  return clock_getres32(clock_id, (struct _timespec32*) res);
+#else
+  return clock_getres64(clock_id, (struct _timespec64*) res);
+#endif
+}
+#endif
+
+WINPTHREAD_API int __cdecl clock_gettime32(clockid_t clock_id, struct 
_timespec32 *tp);
+WINPTHREAD_API int __cdecl clock_gettime64(clockid_t clock_id, struct 
_timespec64 *tp);
+#ifdef IN_WINPTHREAD
 WINPTHREAD_API int __cdecl clock_gettime(clockid_t clock_id, struct timespec 
*tp);
+#else
+static WINPTHREADS_ALWAYS_INLINE int __cdecl clock_gettime(clockid_t clock_id, 
struct timespec *tp)
+{
+#if defined(_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32)
+  return clock_gettime32(clock_id, (struct _timespec32*) tp);
+#else
+  return clock_gettime64(clock_id, (struct _timespec64*) tp);
+#endif
+}
+#endif
+
+WINPTHREAD_API int __cdecl clock_settime32(clockid_t clock_id, const struct 
_timespec32 *tp);
+WINPTHREAD_API int __cdecl clock_settime64(clockid_t clock_id, const struct 
_timespec64 *tp);
+#ifdef IN_WINPTHREAD
 WINPTHREAD_API int __cdecl clock_settime(clockid_t clock_id, const struct 
timespec *tp);
+#else
+static WINPTHREADS_ALWAYS_INLINE int __cdecl clock_settime(clockid_t clock_id, 
const struct timespec *tp)
+{
+#if defined(_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32)
+  return clock_settime32(clock_id, (const struct _timespec32*) tp);
+#else
+  return clock_settime64(clock_id, (const struct _timespec64*) tp);
+#endif
+}
+#endif
 
 #ifdef __cplusplus
 }
diff --git a/mingw-w64-libraries/winpthreads/include/semaphore.h 
b/mingw-w64-libraries/winpthreads/include/semaphore.h
index b6cd13f16..fb78a1943 100644
--- a/mingw-w64-libraries/winpthreads/include/semaphore.h
+++ b/mingw-w64-libraries/winpthreads/include/semaphore.h
@@ -43,7 +43,19 @@ WINPTHREAD_API int sem_trywait(sem_t *sem);
 
 WINPTHREAD_API int sem_wait(sem_t *sem);
 
+WINPTHREAD_API int sem_timedwait64(sem_t * sem, const struct _timespec64 *t);
+WINPTHREAD_API int sem_timedwait32(sem_t * sem, const struct _timespec32 *t);
+#ifdef IN_WINPTHREAD
 WINPTHREAD_API int sem_timedwait(sem_t * sem, const struct timespec *t);
+#else
+static WINPTHREADS_ALWAYS_INLINE int sem_timedwait(sem_t *sem, const struct 
timespec *t) {
+#if defined (_USE_32BIT_TIME_T) || (defined(_TIME_BITS) && _TIME_BITS == 32)
+  return sem_timedwait32 (sem, (const struct _timespec32*) t);
+#else
+  return sem_timedwait64 (sem, (const struct _timespec64*) t);
+#endif
+}
+#endif
 
 WINPTHREAD_API int sem_post(sem_t *sem);
 
diff --git a/mingw-w64-libraries/winpthreads/src/barrier.c 
b/mingw-w64-libraries/winpthreads/src/barrier.c
index e973aaaa7..8bf62412e 100644
--- a/mingw-w64-libraries/winpthreads/src/barrier.c
+++ b/mingw-w64-libraries/winpthreads/src/barrier.c
@@ -20,12 +20,16 @@
    DEALINGS IN THE SOFTWARE.
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <windows.h>
 #include <stdio.h>
 #include <malloc.h>
 #include "pthread.h"
 #include "barrier.h"
-#include "ref.h" 
+#include "ref.h"
 #include "misc.h"
 
 static pthread_spinlock_t barrier_global = PTHREAD_SPINLOCK_INITIALIZER;
@@ -64,7 +68,7 @@ barrier_ref_destroy(volatile pthread_barrier_t *barrier, 
pthread_barrier_t *bDes
 
     *bDestroy = NULL;
     pthread_spin_lock(&barrier_global);
-    
+
     if (!barrier || !*barrier || ((barrier_t *)*barrier)->valid != 
LIFE_BARRIER) r = EINVAL;
     else {
         barrier_t *b_ = (barrier_t *)*barrier;
@@ -92,15 +96,15 @@ int pthread_barrier_destroy(pthread_barrier_t *b_)
     pthread_barrier_t bDestroy;
     barrier_t *b;
     int r;
-    
+
     while ((r = barrier_ref_destroy(b_,&bDestroy)) == EBUSY)
       Sleep(0);
-    
+
     if (r)
       return r;
 
     b = (barrier_t *)bDestroy;
-    
+
     pthread_mutex_lock(&b->m);
 
     if (sem_destroy(&b->sems[0]) != 0)
diff --git a/mingw-w64-libraries/winpthreads/src/clock.c 
b/mingw-w64-libraries/winpthreads/src/clock.c
index 954d845b1..b1a63ecbf 100644
--- a/mingw-w64-libraries/winpthreads/src/clock.c
+++ b/mingw-w64-libraries/winpthreads/src/clock.c
@@ -4,7 +4,13 @@
  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <assert.h>
 #include <errno.h>
+#include <limits.h>
 #include <stdint.h>
 #include <time.h>
 #include <windows.h>
@@ -17,6 +23,7 @@
 
 #define POW10_7                 10000000
 #define POW10_9                 1000000000
+#define TIME32_MAX              INT_MAX
 
 /* Number of 100ns-seconds between the beginning of the Windows epoch
  * (Jan. 1, 1601) and the Unix epoch (Jan. 1, 1970)
@@ -51,7 +58,7 @@ static WINPTHREADS_INLINE int lc_set_errno(int result)
  *         If the function fails, the return value is -1,
  *         with errno set to indicate the error.
  */
-int clock_getres(clockid_t clock_id, struct timespec *res)
+static int __pthread_clock_getres(clockid_t clock_id, struct _timespec64 *res)
 {
     clockid_t id = clock_id;
 
@@ -113,7 +120,7 @@ int clock_getres(clockid_t clock_id, struct timespec *res)
  *         If the function fails, the return value is -1,
  *         with errno set to indicate the error.
  */
-int clock_gettime(clockid_t clock_id, struct timespec *tp)
+static int __pthread_clock_gettime(clockid_t clock_id, struct _timespec64 *tp)
 {
     unsigned __int64 t;
     LARGE_INTEGER pf, pc;
@@ -172,7 +179,7 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
         return 0;
         }
 
-    case CLOCK_THREAD_CPUTIME_ID: 
+    case CLOCK_THREAD_CPUTIME_ID:
         {
             if(0 == GetThreadTimes(GetCurrentThread(), &ct.ft, &et.ft, &kt.ft, 
&ut.ft))
                 return lc_set_errno(EINVAL);
@@ -201,20 +208,20 @@ int clock_gettime(clockid_t clock_id, struct timespec *tp)
  *         If the function fails, the return value is -1,
  *         with errno set to indicate the error.
  */
-int clock_nanosleep(clockid_t clock_id, int flags,
-                           const struct timespec *request,
-                           struct timespec *remain)
+static int __pthread_clock_nanosleep(clockid_t clock_id, int flags,
+                           const struct _timespec64 *request,
+                           struct _timespec64 *remain)
 {
-    struct timespec tp;
+    struct _timespec64 tp;
 
     if (clock_id != CLOCK_REALTIME)
         return lc_set_errno(EINVAL);
 
     if (flags == 0)
-        return nanosleep(request, remain);
+        return nanosleep64(request, remain);
 
     /* TIMER_ABSTIME = 1 */
-    clock_gettime(CLOCK_REALTIME, &tp);
+    __pthread_clock_gettime(CLOCK_REALTIME, &tp);
 
     tp.tv_sec = request->tv_sec - tp.tv_sec;
     tp.tv_nsec = request->tv_nsec - tp.tv_nsec;
@@ -223,7 +230,7 @@ int clock_nanosleep(clockid_t clock_id, int flags,
         tp.tv_sec --;
     }
 
-    return nanosleep(&tp, remain);
+    return nanosleep64(&tp, remain);
 }
 
 /**
@@ -234,7 +241,7 @@ int clock_nanosleep(clockid_t clock_id, int flags,
  *         If the function fails, the return value is -1,
  *         with errno set to indicate the error.
  */
-int clock_settime(clockid_t clock_id, const struct timespec *tp)
+static int __pthread_clock_settime(clockid_t clock_id, const struct 
_timespec64 *tp)
 {
     SYSTEMTIME st;
 
@@ -255,3 +262,138 @@ int clock_settime(clockid_t clock_id, const struct 
timespec *tp)
 
     return 0;
 }
+
+/**
+ * Versions to use with 64-bit `time_t`.
+ */
+
+int clock_getres64 (clockid_t clock_id, struct _timespec64 *res)
+{
+    return __pthread_clock_getres (clock_id, res);
+}
+
+int clock_gettime64 (clockid_t clock_id, struct _timespec64 *tp)
+{
+    return __pthread_clock_gettime (clock_id, tp);
+}
+
+int clock_settime64 (clockid_t clock_id, const struct _timespec64 *tp)
+{
+    return __pthread_clock_settime (clock_id, tp);
+}
+
+int clock_nanosleep64 (clockid_t clock_id, int flags, const struct _timespec64 
*request, struct _timespec64 *remain)
+{
+    return __pthread_clock_nanosleep (clock_id, flags, request, remain);
+}
+
+/**
+ * Versions to use with 32-bit `time_t`.
+ */
+
+int clock_getres32 (clockid_t clock_id, struct _timespec32 *res)
+{
+    struct _timespec64 ts64 = {0};
+
+    int rc = __pthread_clock_getres (clock_id, &ts64);
+
+    if (rc == -1)
+        return -1;
+
+    res->tv_sec = ts64.tv_sec;
+    res->tv_nsec = ts64.tv_nsec;
+
+    return 0;
+}
+
+int clock_gettime32 (clockid_t clock_id, struct _timespec32 *tp)
+{
+    struct _timespec64 ts64 = {0};
+
+    int rc = __pthread_clock_gettime (clock_id, &ts64);
+
+    if (rc == -1)
+        return -1;
+
+    if (ts64.tv_sec > TIME32_MAX) {
+        _set_errno (ERANGE);
+        return -1;
+    }
+
+    tp->tv_sec = ts64.tv_sec;
+    tp->tv_nsec = ts64.tv_nsec;
+
+    return 0;
+}
+
+int clock_settime32 (clockid_t clock_id, const struct _timespec32 *tp)
+{
+    struct _timespec64 ts64 = {.tv_sec = tp->tv_sec, .tv_nsec = tp->tv_nsec};
+    return __pthread_clock_settime (clock_id, &ts64);
+}
+
+int clock_nanosleep32 (clockid_t clock_id, int flags, const struct _timespec32 
*request, struct _timespec32 *remain)
+{
+    struct _timespec64 remain64 = {0};
+    struct _timespec64 request64 = {
+        .tv_sec = request->tv_sec,
+        .tv_nsec = request->tv_nsec
+    };
+
+    int rc = __pthread_clock_nanosleep (clock_id, flags, &request64, 
&remain64);
+
+    if (rc == -1)
+        return -1;
+
+#ifdef WINPTHREAD_DBG
+    assert (remain64.tv_sec <= TIME32_MAX);
+#endif
+
+    if (remain != NULL) {
+        remain->tv_sec = remain64.tv_sec;
+        remain->tv_nsec = remain64.tv_nsec;
+    }
+
+    return 0;
+}
+
+/**
+ * Provide default external symbols which uses `time_t` of the same size
+ * as used during configuration.
+ */
+
+int clock_getres (clockid_t clock_id, struct timespec *res)
+{
+#if SIZEOF_TIME_T == 8
+    return clock_getres64 (clock_id, (struct _timespec64 *) res);
+#else
+    return clock_getres32 (clock_id, (struct _timespec32 *) res);
+#endif
+}
+
+int clock_gettime (clockid_t clock_id, struct timespec *tp)
+{
+#if SIZEOF_TIME_T == 8
+    return clock_gettime64 (clock_id, (struct _timespec64 *) tp);
+#else
+    return clock_gettime32 (clock_id, (struct _timespec32 *) tp);
+#endif
+}
+
+int clock_settime (clockid_t clock_id, const struct timespec *tp)
+{
+#if SIZEOF_TIME_T == 8
+    return clock_settime64 (clock_id, (const struct _timespec64 *) tp);
+#else
+    return clock_settime32 (clock_id, (const struct _timespec32 *) tp);
+#endif
+}
+
+int clock_nanosleep (clockid_t clock_id, int flags, const struct timespec 
*request, struct timespec *remain)
+{
+#if SIZEOF_TIME_T == 8
+    return clock_nanosleep64 (clock_id, flags, (const struct _timespec64 *) 
request, (struct _timespec64 *) remain);
+#else
+    return clock_nanosleep32 (clock_id, flags, (const struct _timespec32 *) 
request, (struct _timespec32 *) remain);
+#endif
+}
diff --git a/mingw-w64-libraries/winpthreads/src/cond.c 
b/mingw-w64-libraries/winpthreads/src/cond.c
index 813648f0e..37261385f 100644
--- a/mingw-w64-libraries/winpthreads/src/cond.c
+++ b/mingw-w64-libraries/winpthreads/src/cond.c
@@ -20,6 +20,10 @@
    DEALINGS IN THE SOFTWARE.
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 /*
  * Posix Condition Variables for Microsoft Windows.
  * 22-9-2010 Partly based on the ACE framework implementation.
@@ -72,7 +76,7 @@ void cond_print(volatile pthread_cond_t *c, char *txt)
         fprintf(fo,"C%p %lu V=%0X w=%ld %s\n",
             (void *)*c,
             GetCurrentThreadId(),
-            (int)c_->valid, 
+            (int)c_->valid,
             c_->waiters_count_,
             txt
             );
@@ -86,7 +90,7 @@ static int
 cond_static_init (pthread_cond_t *c)
 {
   int r = 0;
-  
+
   pthread_spin_lock (&cond_locked);
   if (c == NULL)
     r = EINVAL;
@@ -143,40 +147,6 @@ pthread_condattr_setclock(pthread_condattr_t *a, clockid_t 
clock_id)
   return 0;
 }
 
-int
-__pthread_clock_nanosleep (clockid_t clock_id, int flags, const struct 
timespec *rqtp,
-                          struct timespec *rmtp)
-{
-  unsigned long long tick, tick2;
-  unsigned long long delay;
-  DWORD dw;
-
-  if (clock_id != CLOCK_REALTIME
-      && clock_id != CLOCK_MONOTONIC
-      && clock_id != CLOCK_PROCESS_CPUTIME_ID)
-   return EINVAL;
-  if ((flags & TIMER_ABSTIME) != 0)
-    delay = _pthread_rel_time_in_ms (rqtp);
-  else
-    delay = _pthread_time_in_ms_from_timespec (rqtp);
-  do
-    {
-      dw = (DWORD) (delay >= 99999ULL ? 99999ULL : delay);
-      tick = _pthread_time_in_ms ();
-      pthread_delay_np_ms (dw);
-      tick2 = _pthread_time_in_ms ();
-      tick2 -= tick;
-      if (tick2 >= delay)
-        delay = 0;
-      else
-        delay -= tick2;
-    }
-  while (delay != 0ULL);
-  if (rmtp)
-    memset (rmtp, 0, sizeof (*rmtp));
-  return 0;
-}
-
 int
 pthread_condattr_setpshared (pthread_condattr_t *a, int s)
 {
@@ -218,7 +188,7 @@ pthread_cond_init (pthread_cond_t *c, const 
pthread_condattr_t *a)
   _c->sema_b =  CreateSemaphore (NULL,       /* no security */
       0,          /* initially 0 */
       0x7fffffff, /* max count */
-      NULL);  
+      NULL);
   if (_c->sema_q == NULL || _c->sema_b == NULL) {
       if (_c->sema_q != NULL)
        CloseHandle (_c->sema_q);
@@ -356,7 +326,7 @@ pthread_cond_broadcast (pthread_cond_t *c)
 {
   cond_t *_c;
   int r;
-  int relCnt = 0;    
+  int relCnt = 0;
 
   if (!c || !*c)
     return EINVAL;
@@ -465,7 +435,7 @@ tryagain:
 }
 
 static int
-pthread_cond_timedwait_impl (pthread_cond_t *c, pthread_mutex_t 
*external_mutex, const struct timespec *t, int rel)
+pthread_cond_timedwait_impl (pthread_cond_t *c, pthread_mutex_t 
*external_mutex, const struct _timespec64 *t, int rel)
 {
   sCondWaitHelper ch;
   DWORD dwr;
@@ -530,18 +500,58 @@ tryagain:
   return r;
 }
 
+/* Version to use with 64-bit `time_t`. */
 int
-pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, const struct 
timespec *t)
+pthread_cond_timedwait64(pthread_cond_t *c, pthread_mutex_t *m, const struct 
_timespec64 *t)
 {
   return pthread_cond_timedwait_impl(c, m, t, 0);
 }
 
+/* Version to use with 64-bit `time_t`. */
 int
-pthread_cond_timedwait_relative_np(pthread_cond_t *c, pthread_mutex_t *m, 
const struct timespec *t)
+pthread_cond_timedwait64_relative_np(pthread_cond_t *c, pthread_mutex_t *m, 
const struct _timespec64 *t)
 {
   return pthread_cond_timedwait_impl(c, m, t, 1);
 }
 
+/* Version to use with 32-bit `time_t`. */
+int
+pthread_cond_timedwait32(pthread_cond_t *c, pthread_mutex_t *m, const struct 
_timespec32 *t)
+{
+  struct _timespec64 t64 = {.tv_sec = t->tv_sec, .tv_nsec = t->tv_nsec};
+  return pthread_cond_timedwait_impl(c, m, &t64, 0);
+}
+
+/* Version to use with 32-bit `time_t`. */
+int
+pthread_cond_timedwait32_relative_np(pthread_cond_t *c, pthread_mutex_t *m, 
const struct _timespec32 *t)
+{
+  struct _timespec64 t64 = {.tv_sec = t->tv_sec, .tv_nsec = t->tv_nsec};
+  return pthread_cond_timedwait_impl(c, m, &t64, 1);
+}
+
+/* Default external symbol. */
+int
+pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, const struct 
timespec *t)
+{
+#if SIZEOF_TIME_T == 8
+  return pthread_cond_timedwait64 (c, m, (const struct _timespec64*) t);
+#else
+  return pthread_cond_timedwait32 (c, m, (const struct _timespec32*) t);
+#endif
+}
+
+/* Default external symbol. */
+int
+pthread_cond_timedwait_relative_np(pthread_cond_t *c, pthread_mutex_t *m, 
const struct timespec *t)
+{
+#if SIZEOF_TIME_T == 8
+  return pthread_cond_timedwait64_relative_np (c, m, (const struct 
_timespec64*) t);
+#else
+  return pthread_cond_timedwait32_relative_np (c, m, (const struct 
_timespec32*) t);
+#endif
+}
+
 static void
 cleanup_wait (void *arg)
 {
@@ -751,5 +761,5 @@ do_sema_b_release(HANDLE sema, LONG count,CRITICAL_SECTION 
*cs, LONG *val)
   }
   InterlockedExchangeAdd(val, -count);
   LeaveCriticalSection(cs);
-  return EINVAL;  
+  return EINVAL;
 }
diff --git a/mingw-w64-libraries/winpthreads/src/misc.c 
b/mingw-w64-libraries/winpthreads/src/misc.c
index c426f59cb..0645060ea 100644
--- a/mingw-w64-libraries/winpthreads/src/misc.c
+++ b/mingw-w64-libraries/winpthreads/src/misc.c
@@ -20,6 +20,10 @@
    DEALINGS IN THE SOFTWARE.
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <windows.h>
 #include "pthread.h"
 #include "misc.h"
@@ -82,7 +86,7 @@ unsigned long long _pthread_time_in_ms(void)
             - 0x19DB1DED53E8000ULL) / 10000ULL;
 }
 
-unsigned long long _pthread_time_in_ms_from_timespec(const struct timespec *ts)
+unsigned long long _pthread_time_in_ms_from_timespec(const struct _timespec64 
*ts)
 {
     unsigned long long t = (unsigned long long) ts->tv_sec * 1000LL;
     /* The +999999 is here to ensure that the division always rounds up */
@@ -91,7 +95,7 @@ unsigned long long _pthread_time_in_ms_from_timespec(const 
struct timespec *ts)
     return t;
 }
 
-unsigned long long _pthread_rel_time_in_ms(const struct timespec *ts)
+unsigned long long _pthread_rel_time_in_ms(const struct _timespec64 *ts)
 {
     unsigned long long t1 = _pthread_time_in_ms_from_timespec(ts);
     unsigned long long t2 = _pthread_time_in_ms();
diff --git a/mingw-w64-libraries/winpthreads/src/misc.h 
b/mingw-w64-libraries/winpthreads/src/misc.h
index a853dd085..76db2cc09 100644
--- a/mingw-w64-libraries/winpthreads/src/misc.h
+++ b/mingw-w64-libraries/winpthreads/src/misc.h
@@ -102,8 +102,8 @@ static WINPTHREADS_INLINE unsigned long 
dwMilliSecs(unsigned long long ms)
 }
 
 unsigned long long _pthread_time_in_ms(void);
-unsigned long long _pthread_time_in_ms_from_timespec(const struct timespec 
*ts);
-unsigned long long _pthread_rel_time_in_ms(const struct timespec *ts);
+unsigned long long _pthread_time_in_ms_from_timespec(const struct _timespec64 
*ts);
+unsigned long long _pthread_rel_time_in_ms(const struct _timespec64 *ts);
 unsigned long _pthread_wait_for_single_object (void *handle, unsigned long 
timeout);
 unsigned long _pthread_wait_for_multiple_objects (unsigned long count, void 
**handles, unsigned int all, unsigned long timeout);
 
diff --git a/mingw-w64-libraries/winpthreads/src/mutex.c 
b/mingw-w64-libraries/winpthreads/src/mutex.c
index 866e18d94..d5362af03 100644
--- a/mingw-w64-libraries/winpthreads/src/mutex.c
+++ b/mingw-w64-libraries/winpthreads/src/mutex.c
@@ -21,6 +21,10 @@
    DEALINGS IN THE SOFTWARE.
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <windows.h>
 #include <stdio.h>
 #include <malloc.h>
@@ -184,7 +188,8 @@ pthread_mutex_lock (pthread_mutex_t *m)
   return pthread_mutex_lock_intern (m, INFINITE);
 }
 
-int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *ts)
+/* Internal version which always used `struct _timespec64`. */
+static int __pthread_mutex_timedlock(pthread_mutex_t *m, const struct 
_timespec64 *ts)
 {
   unsigned long long patience;
   if (ts != NULL) {
@@ -199,8 +204,31 @@ int pthread_mutex_timedlock(pthread_mutex_t *m, const 
struct timespec *ts)
   return pthread_mutex_lock_intern(m, patience);
 }
 
+/* Version to use with 64-bit `time_t`. */
+int pthread_mutex_timedlock64(pthread_mutex_t *m, const struct _timespec64 *ts)
+{
+  return __pthread_mutex_timedlock (m, ts);
+}
+
+/* Version to use with 32-bit `time_t`. */
+int pthread_mutex_timedlock32(pthread_mutex_t *m, const struct _timespec32 *ts)
+{
+  struct _timespec64 ts64 = {.tv_sec = ts->tv_sec, .tv_nsec = ts->tv_nsec};
+  return __pthread_mutex_timedlock (m, &ts64);
+}
+
+/* Default external symbol. */
+int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *ts)
+{
+#if SIZEOF_TIME_T == 8
+  return pthread_mutex_timedlock64 (m, (const struct _timespec64*) ts);
+#else
+  return pthread_mutex_timedlock32 (m, (const struct _timespec32*) ts);
+#endif
+}
+
 int pthread_mutex_unlock(pthread_mutex_t *m)
-{    
+{
   /* Here m might an initialiser of an error-checking or recursive mutex, in
      which case the behaviour is well-defined, so we can't skip this check. */
   mutex_impl_t *mi = mutex_impl(m);
@@ -305,9 +333,9 @@ int pthread_mutexattr_gettype(const pthread_mutexattr_t *a, 
int *type)
 {
   if (!a || !type)
     return EINVAL;
-       
+
   *type = *a & 3;
-  
+
   return 0;
 }
 
diff --git a/mingw-w64-libraries/winpthreads/src/nanosleep.c 
b/mingw-w64-libraries/winpthreads/src/nanosleep.c
index 0cce4492e..3462878fb 100644
--- a/mingw-w64-libraries/winpthreads/src/nanosleep.c
+++ b/mingw-w64-libraries/winpthreads/src/nanosleep.c
@@ -4,7 +4,13 @@
  * No warranty is given; refer to the file DISCLAIMER.PD within this package.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <assert.h>
 #include <errno.h>
+#include <limits.h>
 #include <time.h>
 #include <windows.h>
 #include "pthread.h"
@@ -16,6 +22,7 @@
 #define POW10_6                 1000000
 #define POW10_9                 1000000000
 #define MAX_SLEEP_IN_MS         4294967294UL
+#define TIME32_MAX              INT_MAX
 
 /**
  * Sleep for the specified time.
@@ -25,7 +32,7 @@
  *         If the function fails, the return value is -1,
  *         with errno set to indicate the error.
  */
-int nanosleep(const struct timespec *request, struct timespec *remain)
+static int __nanosleep(const struct _timespec64 *request, struct _timespec64 
*remain)
 {
     unsigned long ms, rc = 0;
     unsigned __int64 u64, want, real;
@@ -69,3 +76,45 @@ int nanosleep(const struct timespec *request, struct 
timespec *remain)
 
     return 0;
 }
+
+/* Versions to use with 64-bit `time_t`. */
+int nanosleep64(const struct _timespec64 *request, struct _timespec64 *remain)
+{
+    return __nanosleep (request, remain);
+}
+
+/* Versions to use with 32-bit `time_t`. */
+int nanosleep32(const struct _timespec32 *request, struct _timespec32 *remain)
+{
+    struct _timespec64 remain64 = {0};
+    struct _timespec64 request64 = {
+        .tv_sec = request->tv_sec,
+        .tv_nsec = request->tv_nsec
+    };
+
+    int rc = __nanosleep (&request64, &remain64);
+
+    if (rc == -1)
+        return -1;
+
+#ifdef WINPTHREAD_DBG
+    assert (remain64.tv_sec <= TIME32_MAX);
+#endif
+
+    if (remain != NULL) {
+        remain->tv_sec = remain64.tv_sec;
+        remain->tv_nsec = remain64.tv_nsec;
+    }
+
+    return 0;
+}
+
+/* Default external symbol. */
+int nanosleep (const struct timespec *request, struct timespec *remain)
+{
+#if SIZEOF_TIME_T == 8
+    return nanosleep64 ((struct _timespec64 *) request, (struct _timespec64 *) 
remain);
+#else
+    return nanosleep32 ((struct _timespec32 *) request, (struct _timespec32 *) 
remain);
+#endif
+}
diff --git a/mingw-w64-libraries/winpthreads/src/rwlock.c 
b/mingw-w64-libraries/winpthreads/src/rwlock.c
index 76669dff1..3e033e6f9 100644
--- a/mingw-w64-libraries/winpthreads/src/rwlock.c
+++ b/mingw-w64-libraries/winpthreads/src/rwlock.c
@@ -20,6 +20,10 @@
    DEALINGS IN THE SOFTWARE.
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <windows.h>
 #include <stdio.h>
 #include <malloc.h>
@@ -87,7 +91,7 @@ static WINPTHREADS_ATTRIBUTE((noinline)) int 
rwl_ref_destroy(pthread_rwlock_t *r
 
     *rDestroy = (pthread_rwlock_t)NULL;
     pthread_spin_lock(&rwl_global);
-    
+
     if (!rwl || !*rwl) r = EINVAL;
     else {
         rwlock_t *r_ = (rwlock_t *)*rwl;
@@ -145,7 +149,7 @@ void rwl_print(volatile pthread_rwlock_t *rwl, char *txt)
         printf("RWL%p %lu V=%0X B=%d r=%ld w=%ld L=%p %s\n",
             (void *)*rwl,
             GetCurrentThreadId(),
-            (int)r->valid, 
+            (int)r->valid,
             (int)r->busy,
             0L,0L,NULL,txt);
     }
@@ -165,7 +169,7 @@ static WINPTHREADS_ATTRIBUTE((noinline)) int 
rwlock_static_init(pthread_rwlock_t
   }
   r = pthread_rwlock_init (rw, NULL);
   pthread_spin_unlock(&cond_locked);
-  
+
   return r;
 }
 
@@ -178,7 +182,7 @@ int pthread_rwlock_init (pthread_rwlock_t *rwlock_, const 
pthread_rwlockattr_t *
       return EINVAL;
     *rwlock_ = (pthread_rwlock_t)NULL;
     if ((rwlock = calloc(1, sizeof(*rwlock))) == NULL)
-      return ENOMEM; 
+      return ENOMEM;
     rwlock->valid = DEAD_RWLOCK;
 
     rwlock->nex_count = rwlock->nsh_count = rwlock->ncomplete = 0;
@@ -203,18 +207,18 @@ int pthread_rwlock_init (pthread_rwlock_t *rwlock_, const 
pthread_rwlockattr_t *
     rwlock->valid = LIFE_RWLOCK;
     *rwlock_ = (pthread_rwlock_t)rwlock;
     return r;
-} 
+}
 
 int pthread_rwlock_destroy (pthread_rwlock_t *rwlock_)
 {
     rwlock_t *rwlock;
     pthread_rwlock_t rDestroy;
     int r, r2;
-    
+
     pthread_spin_lock(&cond_locked);
     r = rwl_ref_destroy(rwlock_,&rDestroy);
     pthread_spin_unlock(&cond_locked);
-    
+
     if(r) return r;
     if(!rDestroy) return 0; /* destroyed a (still) static initialized rwl */
 
@@ -245,7 +249,7 @@ int pthread_rwlock_destroy (pthread_rwlock_t *rwlock_)
     rwlock->valid  = DEAD_RWLOCK;
     free((void *)rDestroy);
     return 0;
-} 
+}
 
 int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock_)
 {
@@ -279,7 +283,8 @@ int pthread_rwlock_rdlock (pthread_rwlock_t *rwlock_)
   return rwl_unref(rwlock_, ret);
 }
 
-int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, const struct 
timespec *ts)
+/* Internal version which always uses `struct _timespec64`. */
+static int __pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, const 
struct _timespec64 *ts)
 {
   rwlock_t *rwlock;
   int ret;
@@ -290,12 +295,12 @@ int pthread_rwlock_timedrdlock (pthread_rwlock_t 
*rwlock_, const struct timespec
   if(ret != 0) return ret;
 
   rwlock = (rwlock_t *)*rwlock_;
-  if ((ret = pthread_mutex_timedlock (&rwlock->mex, ts)) != 0)
+  if ((ret = pthread_mutex_timedlock64 (&rwlock->mex, ts)) != 0)
       return rwl_unref(rwlock_, ret);
   InterlockedIncrement(&rwlock->nsh_count);
   if (rwlock->nsh_count == INT_MAX)
   {
-    ret = pthread_mutex_timedlock(&rwlock->mcomplete, ts);
+    ret = pthread_mutex_timedlock64(&rwlock->mcomplete, ts);
     if (ret != 0)
     {
       if (ret == ETIMEDOUT)
@@ -312,6 +317,29 @@ int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, 
const struct timespec
   return rwl_unref(rwlock_, ret);
 }
 
+/* Version to use with 64-bit `time_t`. */
+int pthread_rwlock_timedrdlock64 (pthread_rwlock_t *rwlock_, const struct 
_timespec64 *ts)
+{
+  return __pthread_rwlock_timedrdlock (rwlock_, ts);
+}
+
+/* Version to use with 32-bit `time_t`. */
+int pthread_rwlock_timedrdlock32 (pthread_rwlock_t *rwlock_, const struct 
_timespec32 *ts)
+{
+  struct _timespec64 ts64 = {.tv_sec = ts->tv_sec, .tv_nsec = ts->tv_nsec};
+  return __pthread_rwlock_timedrdlock (rwlock_, &ts64);
+}
+
+/* Default external symbol. */
+int pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock_, const struct 
timespec *ts)
+{
+#if SIZEOF_TIME_T == 8
+  return pthread_rwlock_timedrdlock64 (rwlock_, (const struct _timespec64*) 
ts);
+#else
+  return pthread_rwlock_timedrdlock32 (rwlock_, (const struct _timespec32*) 
ts);
+#endif
+}
+
 int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock_)
 {
   rwlock_t *rwlock;
@@ -340,7 +368,7 @@ int pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock_)
   }
   ret = pthread_mutex_unlock(&rwlock->mex);
   return rwl_unref(rwlock_,ret);
-} 
+}
 
 int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock_)
 {
@@ -378,7 +406,7 @@ int pthread_rwlock_trywrlock (pthread_rwlock_t *rwlock_)
   }
   rwlock->nex_count = 1;
   return rwl_unref(rwlock_, 0);
-} 
+}
 
 int pthread_rwlock_unlock (pthread_rwlock_t *rwlock_)
 {
@@ -409,7 +437,7 @@ int pthread_rwlock_unlock (pthread_rwlock_t *rwlock_)
     ret = rwlock_free_both_locks(rwlock, 0);
   }
   return rwl_unref(rwlock_, ret);
-} 
+}
 
 static void st_cancelwrite (void *arg)
 {
@@ -459,7 +487,8 @@ int pthread_rwlock_wrlock (pthread_rwlock_t *rwlock_)
   return rwl_unref(rwlock_,ret);
 }
 
-int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct 
timespec *ts)
+/* Internal version which always uses `struct _timespec64`. */
+static int __pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const 
struct _timespec64 *ts)
 {
   int ret;
   rwlock_t *rwlock;
@@ -471,10 +500,10 @@ int pthread_rwlock_timedwrlock (pthread_rwlock_t 
*rwlock_, const struct timespec
     return ret;
   rwlock = (rwlock_t *)*rwlock_;
 
-  ret = pthread_mutex_timedlock(&rwlock->mex, ts);
+  ret = pthread_mutex_timedlock64(&rwlock->mex, ts);
   if (ret != 0)
     return rwl_unref(rwlock_,ret);
-  ret = pthread_mutex_timedlock (&rwlock->mcomplete, ts);
+  ret = pthread_mutex_timedlock64 (&rwlock->mcomplete, ts);
   if (ret != 0)
   {
     pthread_mutex_unlock(&rwlock->mex);
@@ -492,7 +521,7 @@ int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, 
const struct timespec
       rwlock->ncomplete = -rwlock->nsh_count;
       pthread_cleanup_push(st_cancelwrite, (void *) rwlock);
       do {
-       ret = pthread_cond_timedwait(&rwlock->ccomplete, &rwlock->mcomplete, 
ts);
+       ret = pthread_cond_timedwait64(&rwlock->ccomplete, &rwlock->mcomplete, 
ts);
       } while (rwlock->ncomplete < 0 && !ret);
       pthread_cleanup_pop(!ret ? 0 : 1);
 
@@ -505,6 +534,29 @@ int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, 
const struct timespec
   return rwl_unref(rwlock_,ret);
 }
 
+/* Version to use with 64-bit `time_t`. */
+int pthread_rwlock_timedwrlock64 (pthread_rwlock_t *rwlock_, const struct 
_timespec64 *ts)
+{
+  return __pthread_rwlock_timedwrlock (rwlock_, ts);
+}
+
+/* Version to use with 32-bit `time_t`. */
+int pthread_rwlock_timedwrlock32 (pthread_rwlock_t *rwlock_, const struct 
_timespec32 *ts)
+{
+  struct _timespec64 ts64 = {.tv_sec = ts->tv_sec, .tv_nsec = ts->tv_nsec};
+  return __pthread_rwlock_timedwrlock (rwlock_, &ts64);
+}
+
+/* Default external symbol. */
+int pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock_, const struct 
timespec *ts)
+{
+#if SIZEOF_TIME_T == 8
+  return pthread_rwlock_timedwrlock64 (rwlock_, (const struct _timespec64*) 
ts);
+#else
+  return pthread_rwlock_timedwrlock32 (rwlock_, (const struct _timespec32*) 
ts);
+#endif
+}
+
 int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a)
 {
   if (!a)
diff --git a/mingw-w64-libraries/winpthreads/src/sched.c 
b/mingw-w64-libraries/winpthreads/src/sched.c
index 976bcc105..c64d62b31 100644
--- a/mingw-w64-libraries/winpthreads/src/sched.c
+++ b/mingw-w64-libraries/winpthreads/src/sched.c
@@ -20,6 +20,10 @@
    DEALINGS IN THE SOFTWARE.
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <windows.h>
 #include <stdio.h>
 #include "pthread.h"
diff --git a/mingw-w64-libraries/winpthreads/src/sem.c 
b/mingw-w64-libraries/winpthreads/src/sem.c
index 340ff69e0..a8d1bdd8a 100644
--- a/mingw-w64-libraries/winpthreads/src/sem.c
+++ b/mingw-w64-libraries/winpthreads/src/sem.c
@@ -20,6 +20,10 @@
    DEALINGS IN THE SOFTWARE.
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <windows.h>
 #include <stdio.h>
 #include <malloc.h>
@@ -212,8 +216,9 @@ sem_wait (sem_t *sem)
   return sem_result (ret);
 }
 
-int
-sem_timedwait (sem_t *sem, const struct timespec *t)
+/* Internal version which always uses `struct _timespec64`. */
+static int
+__sem_timedwait (sem_t *sem, const struct _timespec64 *t)
 {
   int cur_v, ret = 0;
   DWORD dwr;
@@ -251,6 +256,29 @@ sem_timedwait (sem_t *sem, const struct timespec *t)
   return sem_result (ret);
 }
 
+/* Version to use with 64-bit `time_t`. */
+int
+sem_timedwait64 (sem_t *sem, const struct _timespec64 *t) {
+  return __sem_timedwait (sem, t);
+}
+
+/* Version to use with 32-bit `time_t`. */
+int
+sem_timedwait32 (sem_t *sem, const struct _timespec32 *t) {
+  struct _timespec64 t64 = {.tv_sec = t->tv_sec, .tv_nsec = t->tv_nsec};
+  return __sem_timedwait (sem, &t64);
+}
+
+/* Default external symbol. */
+int
+sem_timedwait (sem_t *sem, const struct timespec *t) {
+#if SIZEOF_TIME_T == 8
+  return sem_timedwait64 (sem, (const struct _timespec64*) t);
+#else
+  return sem_timedwait32 (sem, (const struct _timespec32*) t);
+#endif
+}
+
 int
 sem_post (sem_t *sem)
 {
@@ -350,5 +378,5 @@ sem_getvalue (sem_t *sem, int *sval)
 
   *sval = (int) sv->value;
   pthread_mutex_unlock (&sv->vlock);
-  return 0;  
+  return 0;
 }
diff --git a/mingw-w64-libraries/winpthreads/src/thread.c 
b/mingw-w64-libraries/winpthreads/src/thread.c
index d5b3aaa05..6b3ff7d0b 100644
--- a/mingw-w64-libraries/winpthreads/src/thread.c
+++ b/mingw-w64-libraries/winpthreads/src/thread.c
@@ -20,6 +20,10 @@
    DEALINGS IN THE SOFTWARE.
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <windows.h>
 #include <strsafe.h>
 #include <stdio.h>
@@ -677,8 +681,8 @@ pthread_timechange_handler_np(void *dummy)
 
 /* Compatibility routine for pthread-win32.  It waits for ellapse of
    interval and additionally checks for possible thread-cancelation.  */
-int
-pthread_delay_np (const struct timespec *interval)
+static int
+__pthread_delay_np (const struct _timespec64 *interval)
 {
   DWORD to = (!interval ? 0 : dwMilliSecs (_pthread_time_in_ms_from_timespec 
(interval)));
   struct _pthread_v *s = __pthread_self_lite ();
@@ -699,6 +703,32 @@ pthread_delay_np (const struct timespec *interval)
   return 0;
 }
 
+/* Version to use with 64-bit `time_t`. */
+int
+pthread_delay64_np (const struct _timespec64 *interval)
+{
+  return __pthread_delay_np (interval);
+}
+
+/* Version to use with 32-bit `time_t`. */
+int
+pthread_delay32_np (const struct _timespec32 *interval)
+{
+  struct _timespec64 ts64 = {.tv_sec = interval->tv_sec, .tv_nsec = 
interval->tv_nsec};
+  return __pthread_delay_np (&ts64);
+}
+
+/* Default external symbol. */
+int
+pthread_delay_np (const struct timespec *interval)
+{
+#if SIZEOF_TIME_T == 8
+  return pthread_delay64_np ((const struct _timespec64*) interval);
+#else
+  return pthread_delay32_np ((const struct _timespec32*) interval);
+#endif
+}
+
 int pthread_delay_np_ms (DWORD to);
 
 int
@@ -725,7 +755,7 @@ pthread_delay_np_ms (DWORD to)
 /* Compatibility routine for pthread-win32.  It returns the
    amount of available CPUs on system.  */
 int
-pthread_num_processors_np(void) 
+pthread_num_processors_np(void)
 {
   int r = 0;
   DWORD_PTR ProcessAffinityMask, SystemAffinityMask;
@@ -742,10 +772,10 @@ pthread_num_processors_np(void)
 /* Compatiblity routine for pthread-win32.  Allows to set amount of used
    CPUs for process.  */
 int
-pthread_set_num_processors_np(int n) 
+pthread_set_num_processors_np(int n)
 {
   DWORD_PTR ProcessAffinityMask, ProcessNewAffinityMask = 0, 
SystemAffinityMask;
-  int r = 0; 
+  int r = 0;
   /* need at least 1 */
   n = n ? n : 1;
   if (GetProcessAffinityMask (GetCurrentProcess (), &ProcessAffinityMask, 
&SystemAffinityMask))
@@ -878,7 +908,7 @@ pthread_key_delete (pthread_key_t key)
     return EINVAL;
 
   pthread_rwlock_wrlock (&_pthread_key_lock);
-  
+
   _pthread_key_dest[key] = NULL;
 
   /* Start next search from our location */
@@ -910,7 +940,7 @@ pthread_setspecific (pthread_key_t key, const void *value)
 {
   DWORD lasterr = GetLastError ();
   _pthread_v *t = __pthread_self_lite ();
-  
+
   pthread_spin_lock (&t->spin_keys);
 
   if (key >= t->keymax)
-- 
2.46.1.windows.1

From d86fb7955d6b5fcdf83ac7d084b7a8e6d80f55b3 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Tue, 15 Apr 2025 10:10:32 +0900
Subject: [PATCH 5/6] winpthreads: use `mbsrtowcs` instead of `mbstowcs`

`pthread_setname_np` function defined in thread.c uses `mbstowcs` function
which is not thread-safe. Use `mbsrtowcs` instead.

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 mingw-w64-libraries/winpthreads/src/thread.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/src/thread.c 
b/mingw-w64-libraries/winpthreads/src/thread.c
index 6b3ff7d0b..4ce29fa2a 100644
--- a/mingw-w64-libraries/winpthreads/src/thread.c
+++ b/mingw-w64-libraries/winpthreads/src/thread.c
@@ -28,6 +28,7 @@
 #include <strsafe.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <wchar.h>
 #include <malloc.h>
 #include <signal.h>
 #include "pthread.h"
@@ -1911,13 +1912,14 @@ pthread_setname_np (pthread_t thread, const char *name)
 
   if (_pthread_set_thread_description != NULL)
     {
-      size_t required_size = mbstowcs(NULL, name, 0);
+      mbstate_t state = {0};
+      size_t required_size = mbsrtowcs(NULL, &name, 0, &state);
       if (required_size != (size_t)-1)
         {
           wchar_t *wname = malloc((required_size + 1) * sizeof(wchar_t));
           if (wname != NULL)
             {
-              mbstowcs(wname, name, required_size + 1);
+              mbsrtowcs(wname, &name, required_size + 1, &state);
               _pthread_set_thread_description(tv->h, wname);
               free(wname);
             }
-- 
2.46.1.windows.1

From e603b87519c4d15d72e4dafa8a4dfcc4f8850334 Mon Sep 17 00:00:00 2001
From: Kirill Makurin <maiddais...@outlook.com>
Date: Tue, 15 Apr 2025 10:16:19 +0900
Subject: [PATCH 6/6] winpthreads: adjust compiler options when building with
 MSVC

Check for `_MSC_VER` macro instead of checking `$CC` to recognize
MSVC-like compilers. `MSC_VER` is alse defined by `clang-cl.exe`.

Use `-W3` instead of `-Wall` when building with MSVC-link compilers.
The `-Wall` flag is way too noisy.

Add a few more *feature* macros when building with MSVC-like compilers.
This silences warnings about *unsafe* functions and allows to pass
MSVC's `-Zc:__STDC__` compiler option.

Signed-off-by: Kirill Makurin <maiddais...@outlook.com>
---
 mingw-w64-libraries/winpthreads/Makefile.am  |  7 ++++---
 mingw-w64-libraries/winpthreads/configure.ac | 19 ++++++++++++++-----
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/mingw-w64-libraries/winpthreads/Makefile.am 
b/mingw-w64-libraries/winpthreads/Makefile.am
index 5db1636fe..d6caf1005 100644
--- a/mingw-w64-libraries/winpthreads/Makefile.am
+++ b/mingw-w64-libraries/winpthreads/Makefile.am
@@ -1,7 +1,7 @@
 
 SUBDIRS = . tests
 
-AM_CFLAGS = -Wall -DWIN32_LEAN_AND_MEAN
+AM_CFLAGS = -DWIN32_LEAN_AND_MEAN
 ACLOCAL_AMFLAGS = -I m4
 
 lib_LTLIBRARIES = libwinpthread.la
@@ -28,9 +28,10 @@ libwinpthread_la_SOURCES =     \
   src/version.rc
 
 if MSVC
-AM_CFLAGS += -nologo
-libwinpthread_la_CPPFLAGS += -D_CRT_NONSTDC_NO_WARNINGS
+AM_CFLAGS += -W3
+libwinpthread_la_CPPFLAGS += -D_CRT_NONSTDC_NO_WARNINGS 
-D_CRT_DECLARE_NONSTDC_NAMES -D_CRT_SECURE_NO_WARNINGS
 else
+AM_CFLAGS += -Wall
 libwinpthread_la_CPPFLAGS += -D__USE_MINGW_ANSI_STDIO=0
 libwinpthread_la_LDFLAGS += -L$(builddir)/fakelib -Wc,-no-pthread
 EXTRA_libwinpthread_la_DEPENDENCIES = fakelib/libgcc.a  fakelib/libgcc_eh.a  
fakelib/libgcc_s.a
diff --git a/mingw-w64-libraries/winpthreads/configure.ac 
b/mingw-w64-libraries/winpthreads/configure.ac
index fa882495f..43a4a4d21 100644
--- a/mingw-w64-libraries/winpthreads/configure.ac
+++ b/mingw-w64-libraries/winpthreads/configure.ac
@@ -19,11 +19,20 @@ AC_PROG_CC
 AM_PROG_AS
 AM_PROG_AR
 
-AS_CASE([$CC],
-  [*cl|*cl.exe],
-    [RC="$am_aux_dir/windres-rc rc.exe"
-     msvc=true],
-  [msvc=false]])
+AC_COMPILE_IFELSE(
+  [AC_LANG_SOURCE(
+    [
+#if !defined (_MSC_VER)
+not msvc
+#endif
+    ])
+  ],
+dnl then
+    [RC="$am_aux_dir/windres-rc rc.exe"]
+    [msvc=true],
+dnl else
+    [msvc=false]
+)
 AC_SUBST([RCFLAGS])
 AM_CONDITIONAL([MSVC], [test x$msvc = xtrue])
 
-- 
2.46.1.windows.1

_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to