diff --git a/win32.c b/win32.c.new
index e1ac405..cd47bdd 100644
--- a/win32.c
+++ b/win32.c.new
@@ -6942,7 +6942,7 @@ rb_w32_fd_is_text(int fd)
     return _osfile(fd) & FTEXT;
 }
 
-#if RUBY_MSVCRT_VERSION < 80 && !defined(__MINGW64__)
+#if RUBY_MSVCRT_VERSION < 80 && !defined(__MINGW64__) && !defined(__MINGW32__)
 /* License: Ruby's */
 static int
 unixtime_to_systemtime(const time_t t, SYSTEMTIME *st)
@@ -7011,6 +7011,9 @@ systemtime_to_localtime(TIME_ZONE_INFORMATION *tz, SYSTEMTIME *gst, SYSTEMTIME *
 # endif
 # define gmtime_s _gmtime64_s
 # define localtime_s _localtime64_s
+#elif __MINGW32__
+# define gmtime_s _gmtime32_s
+# define localtime_s _localtime32_s
 #endif
 
 /* License: Ruby's */
@@ -7023,7 +7026,7 @@ gmtime_r(const time_t *tp, struct tm *rp)
 	errno = e;
 	return NULL;
     }
-#if RUBY_MSVCRT_VERSION >= 80 || defined(__MINGW64__)
+#if RUBY_MSVCRT_VERSION >= 80 || defined(__MINGW64__) || defined(__MINGW32__)
     e = gmtime_s(rp, tp);
     if (e != 0) goto error;
 #else
@@ -7047,7 +7050,7 @@ localtime_r(const time_t *tp, struct tm *rp)
 	errno = e;
 	return NULL;
     }
-#if RUBY_MSVCRT_VERSION >= 80 || defined(__MINGW64__)
+#if RUBY_MSVCRT_VERSION >= 80 || defined(__MINGW64__) || defined(__MINGW32__)
     e = localtime_s(rp, tp);
     if (e) goto error;
 #else
