On 01/04/15 12:49, Jacek Caban wrote:
> Maybe I missed some better options for us. None of above is perfect and 
> I'm not sure what we should do about it. Solution 2. seems the least 
> problematic.

Looking deeper at this, current implementation has one more problem. We
can't really have localtime_r, because it needs to depend on
_USE_32BIT_TIME_T macro. So if we really wanted to have a real function
in mingwex, we'd need it as localtime32_r and localtime64_r and an
inline wrapper. Given that, I think we should live with inline
implementation. Esp. since we may use localtime_s (which already has
wrapper inline as well as compatibility stub in libmsvcrt.a), which
makes the implementation trivial. Please review the attached patch. I
believe we should do the same for ctime_r and asctime_r.

Jacek
commit ad45ec5b10db1ebae027cce5d970d7c2e17d64c6
Author: Jacek Caban <ja...@codeweavers.com>
Date:   Mon Jan 5 14:00:18 2015 +0100

    time.h: Use inline functions for localtime_r and gmtime_r implementations.

diff --git a/mingw-w64-crt/misc/time_r.c b/mingw-w64-crt/misc/time_r.c
index 8087032..8850e31 100644
--- a/mingw-w64-crt/misc/time_r.c
+++ b/mingw-w64-crt/misc/time_r.c
@@ -12,38 +12,6 @@
  * conversion. Each call to one of these functions destroys the
  * result of any previous call.
  */
-struct tm *__cdecl localtime_r(const time_t *_Time, struct tm *_Tm)
-{
-    struct tm *tmp;
-
-    if (_Time == NULL || _Tm == NULL)
-    {
-        errno = EINVAL;
-        return NULL;
-    }
-
-    tmp = localtime(_Time);
-    if (tmp != NULL)
-        memcpy(_Tm, tmp, sizeof(struct tm));
-    return tmp;
-}
-
-struct tm *__cdecl gmtime_r(const time_t *_Time, struct tm *_Tm)
-{
-    struct tm *tmp;
-
-    if (_Time == NULL || _Tm == NULL)
-    {
-        errno = EINVAL;
-        return NULL;
-    }
-
-    tmp = gmtime(_Time);
-    if (tmp != NULL)
-        memcpy(_Tm, tmp, sizeof(struct tm));
-    return tmp;
-}
-
 char *__cdecl ctime_r(const time_t *_Time, char * _Str)
 {
     char *tmp;
diff --git a/mingw-w64-headers/crt/sec_api/time_s.h 
b/mingw-w64-headers/crt/sec_api/time_s.h
index 6abfaf4..a3f1eec 100644
--- a/mingw-w64-headers/crt/sec_api/time_s.h
+++ b/mingw-w64-headers/crt/sec_api/time_s.h
@@ -43,12 +43,12 @@ __CRT_INLINE errno_t __cdecl _wctime_s (wchar_t 
*_Buffer,size_t _SizeInWords,con
 
 #ifndef RC_INVOKED
 #ifdef _USE_32BIT_TIME_T
-__CRT_INLINE errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { 
return _localtime32_s(_Tm,_Time); }
-__CRT_INLINE errno_t __cdecl gmtime_s(struct tm *_Tm, const time_t *_Time)   { 
return _gmtime32_s(_Tm, _Time); }
+__forceinline errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) 
{ return _localtime32_s(_Tm,_Time); }
+__forceinline errno_t __cdecl gmtime_s(struct tm *_Tm, const time_t *_Time)   
{ return _gmtime32_s(_Tm, _Time); }
 
 #else
-__CRT_INLINE errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) { 
return _localtime64_s(_Tm,_Time); }
-__CRT_INLINE errno_t __cdecl gmtime_s(struct tm *_Tm, const time_t *_Time) { 
return _gmtime64_s(_Tm, _Time); }
+__forceinline errno_t __cdecl localtime_s(struct tm *_Tm,const time_t *_Time) 
{ return _localtime64_s(_Tm,_Time); }
+__forceinline errno_t __cdecl gmtime_s(struct tm *_Tm, const time_t *_Time) { 
return _gmtime64_s(_Tm, _Time); }
 #endif
 #endif
 
diff --git a/mingw-w64-headers/crt/time.h b/mingw-w64-headers/crt/time.h
index e880558..6d415a7 100644
--- a/mingw-w64-headers/crt/time.h
+++ b/mingw-w64-headers/crt/time.h
@@ -169,13 +169,6 @@ char *__cdecl ctime(const time_t *_Time) 
__MINGW_ATTRIB_DEPRECATED_SEC_WARN;
 struct tm *__cdecl gmtime(const time_t *_Time) 
__MINGW_ATTRIB_DEPRECATED_SEC_WARN;
 struct tm *__cdecl localtime(const time_t *_Time) 
__MINGW_ATTRIB_DEPRECATED_SEC_WARN;
 
-#if defined(_POSIX) || defined(_POSIX_THREAD_SAFE_FUNCTIONS)
-struct tm *__cdecl localtime_r(const time_t *_Time, struct tm *_Tm);
-struct tm *__cdecl gmtime_r(const time_t *_Time, struct tm *_Tm);
-char *__cdecl ctime_r(const time_t *_Time, char * _Str);
-char *__cdecl asctime_r(const struct tm *_Tm, char * _Str);
-#endif /* _POSIX */
-
 time_t __cdecl mktime(struct tm *_Tm);
 time_t __cdecl _mkgmtime(struct tm *_Tm);
 time_t __cdecl time(time_t *_Time);
@@ -232,6 +225,17 @@ struct timezone {
 
 #include <sec_api/time_s.h>
 
+#if defined(_POSIX) || defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+__forceinline struct tm *__cdecl localtime_r(const time_t *_Time, struct tm 
*_Tm) {
+  return localtime_s(_Tm, _Time) ? NULL : _Tm;
+}
+__forceinline struct tm *__cdecl gmtime_r(const time_t *_Time, struct tm *_Tm) 
{
+  return gmtime_s(_Tm, _Time) ? NULL : _Tm;
+}
+char *__cdecl ctime_r(const time_t *_Time, char * _Str);
+char *__cdecl asctime_r(const struct tm *_Tm, char * _Str);
+#endif /* _POSIX */
+
 /* Adding timespec definition.  */
 #include <sys/timeb.h>
 
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to