Use gmtime when target is not windows or posix
diff --git a/library/x509.c b/library/x509.c
index 2e6795f..b7e799b 100644
--- a/library/x509.c
+++ b/library/x509.c
@@ -890,6 +890,14 @@
 }
 
 #if defined(MBEDTLS_HAVE_TIME_DATE)
+#if !defined(_WIN32) && (defined(__unix__) || \
+    (defined(__APPLE__) && defined(__MACH__)))
+#include <unistd.h>
+#if !defined(_POSIX_VERSION)
+#define MBEDTLS_X509_USE_GMTIME
+#endif /* !_POSIX_VERSION */
+#endif /* !_WIN32 && (__unix__ || (__APPLE__ && __MACH__)) */
+
 /*
  * Set the time structure to the current time.
  * Return 0 on success, non-zero on failure.
@@ -900,11 +908,20 @@
     mbedtls_time_t tt;
     int ret = 0;
 
+    (void)tm_buf;
+
+#if defined(MBEDTLS_THREADING_C) && defined(MBEDTLS_X509_USE_GMTIME)
+    if( mbedtls_mutex_lock( &mbedtls_threading_gmtime_mutex ) != 0 )
+        return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
+#endif /* MBEDTLS_THREADING_C && MBEDTLS_X509_USE_GMTIME */
+
     tt = mbedtls_time( NULL );
 #if defined(_WIN32) && !defined(EFIX64) && !defined(EFI32)
     lt = gmtime_s( &tm_buf, &tt ) == 0 ? &tm_buf : NULL;
-#else
+#elif defined(_POSIX_VERSION)
     lt = gmtime_r( &tt, &tm_buf );
+#else
+    lt = gmtime( &tt );
 #endif
 
     if( lt == NULL )
@@ -919,6 +936,11 @@
         now->sec  = lt->tm_sec;
     }
 
+#if defined(MBEDTLS_THREADING_C) && defined(MBEDTLS_X509_USE_GMTIME)
+    if( mbedtls_mutex_unlock( &mbedtls_threading_gmtime_mutex ) != 0 )
+        return( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
+#endif /* MBEDTLS_THREADING_C && MBEDTLS_X509_USE_GMTIME */
+
     return( ret );
 }