]> granicus.if.org Git - check/commitdiff
localtime_r.c: provide additional alternatives
authorbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Wed, 25 Dec 2013 03:04:02 +0000 (03:04 +0000)
committerbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Wed, 25 Dec 2013 03:04:02 +0000 (03:04 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@930 64e312b2-a51f-0410-8e61-82d0ca0eb02a

lib/localtime_r.c

index bad2a283b89073420bf5b21694bfda67c554d2fe..d9e9000d23b89d60ed3eec1f83c365d523b21043 100644 (file)
@@ -1,19 +1,24 @@
 #include "libcompat.h"
 
 #if !defined(localtime_r)
-struct tm *
-localtime_r (const time_t *clock, struct tm *result)
+
+struct tm * localtime_r (const time_t *clock, struct tm *result)
 {
-  struct tm *now = localtime (clock);
-  if (now == NULL)
-    {
-      return NULL;
-    }
-  else
+    struct tm *now = NULL;
+
+#if HAVE_LOCALTIME_S
+    localtime_s (now, clock)
+#elif HAVE__LOCALTIME64_S
+    _localtime64_s (now, clock);
+#else
+    now = localtime (clock);
+#endif /* !HAVE_LOCALTIME_S */
+
+    if (now != NULL)
     {
       *result = *now;
     }
-  return result;
+    return result;
 }
 
-#endif
+#endif /* !defined(localtime_r) */