diff --git a/libavutil/time_internal.h b/libavutil/time_internal.h
index c19cc5f73d0859ef474b9a06c63d839cc8aba414..612a75a0411d97b75fc80f05b7c4c010fe05a6eb 100644
--- a/libavutil/time_internal.h
+++ b/libavutil/time_internal.h
@@ -22,7 +22,7 @@
 #include <time.h>
 #include "config.h"
 
-#if !HAVE_GMTIME_R
+#if !HAVE_GMTIME_R && !defined(gmtime_r)
 static inline struct tm *gmtime_r(const time_t* clock, struct tm *result)
 {
     struct tm *ptr = gmtime(clock);
@@ -33,7 +33,7 @@ static inline struct tm *gmtime_r(const time_t* clock, struct tm *result)
 }
 #endif
 
-#if !HAVE_LOCALTIME_R
+#if !HAVE_LOCALTIME_R && !defined(localtime_r)
 static inline struct tm *localtime_r(const time_t* clock, struct tm *result)
 {
     struct tm *ptr = localtime(clock);