evil: simplify implementation of localtime_r
authorVincent Torri <vincent.torri@gmail.com>
Sun, 19 Oct 2014 18:24:50 +0000 (20:24 +0200)
committerCedric BAIL <cedric@osg.samsung.com>
Mon, 20 Oct 2014 16:40:12 +0000 (18:40 +0200)
@fix

src/lib/evil/evil_time.c
src/lib/evil/evil_time.h

index 9bb1ebd..9e6fd5c 100644 (file)
@@ -5,41 +5,19 @@
 #include <strings.h>
 #include <inttypes.h>
 #include <ctype.h>
-#define _POSIX        /* FIXME: to be removed when mingw-w64 will be fixed */
 #include <time.h>
 
 #include "Evil.h"
 #include "evil_private.h"
 
-#ifndef localtime_r
-
 struct tm *
-localtime_r(const time_t *timep, struct tm *result)
+evil_localtime_r(const time_t *timep, struct tm *result)
 {
-# ifndef _MSC_VER
-   struct tm *tmp;
-# endif /* ! _MSC_VER */
-
-   if (!timep || !result)
-     return NULL;
-
-# ifdef _MSC_VER
-   if (localtime_s(result, timep) != 0)
-     return NULL;
-# else
-   tmp = localtime(timep);
-   if (!tmp)
-     return NULL;
-
-   memcpy(result, tmp, sizeof(struct tm));
-
-# endif /* ! _MSC_VER */
+   _localtime64_s(result, timep);
 
    return result;
 }
 
-#endif /* localtime_r */
-
 /*
  * strptime
  * based on http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/time/strptime.c?rev=HEAD
index e137cbd..c65115a 100644 (file)
@@ -14,8 +14,6 @@
  */
 
 
-#ifndef localtime_r
-
 /**
  * @brief Convert the calendar time to broken-time representation in a
  * user supplied data.
  *
  * Supported OS: Windows XP.
  */
-EAPI struct tm *localtime_r(const time_t *timep, struct tm *result);
+EAPI struct tm *evil_localtime_r(const time_t *timep, struct tm *result);
 
-#endif /* localtime_r */
+/**
+ * @def localtime_r(t, r)
+ *
+ * Wrapper around evil_localtime_r().
+ */
+#ifdef localtime_r
+# undef localtime_r
+#endif
+#define localtime_r(t, r) evil_localtime_r(t, r)
 
 /**
  * @brief Convert a string representation of time to a time tm structure .