Piotr Caban : msvcrt: Avoid using localtime_r.

Alexandre Julliard julliard at winehq.org
Mon Mar 29 09:57:59 CDT 2010


Module: wine
Branch: master
Commit: 8c954c09574c12a33a83c04d22ed460dc20048eb
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=8c954c09574c12a33a83c04d22ed460dc20048eb

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Mon Mar 29 00:01:53 2010 +0200

msvcrt: Avoid using localtime_r.

---

 dlls/msvcrt/time.c |   15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/dlls/msvcrt/time.c b/dlls/msvcrt/time.c
index 3b7bb71..d5b0227 100644
--- a/dlls/msvcrt/time.c
+++ b/dlls/msvcrt/time.c
@@ -32,6 +32,7 @@
 #include <limits.h>
 
 #include "msvcrt.h"
+#include "mtdll.h"
 #include "winbase.h"
 #include "winnls.h"
 #include "wine/debug.h"
@@ -127,16 +128,21 @@ MSVCRT___time32_t CDECL MSVCRT_mktime(struct MSVCRT_tm *mstm)
  */
 struct MSVCRT_tm* CDECL MSVCRT__localtime64(const MSVCRT___time64_t* secs)
 {
-    struct tm tm;
+    struct tm *tm;
     thread_data_t *data;
     time_t seconds = *secs;
 
     if (seconds < 0) return NULL;
 
-    if (!localtime_r( &seconds, &tm )) return NULL;
+    _mlock(_TIME_LOCK);
+    if (!(tm = localtime( &seconds))) {
+        _munlock(_TIME_LOCK);
+        return NULL;
+    }
 
     data = msvcrt_get_thread_data();
-    unix_tm_to_msvcrt( &data->time_buffer, &tm );
+    unix_tm_to_msvcrt( &data->time_buffer, tm );
+    _munlock(_TIME_LOCK);
 
     return &data->time_buffer;
 }
@@ -492,12 +498,15 @@ void CDECL MSVCRT__tzset(void)
         struct tm *tmp;
         int zone_january, zone_july;
 
+        _mlock(_TIME_LOCK);
         t = (time(NULL) / seconds_in_year) * seconds_in_year;
         tmp = localtime(&t);
         zone_january = -tmp->tm_gmtoff;
         t += seconds_in_year / 2;
         tmp = localtime(&t);
         zone_july = -tmp->tm_gmtoff;
+        _munlock(_TIME_LOCK);
+
         MSVCRT___daylight = (zone_january != zone_july);
         MSVCRT___timezone = max(zone_january, zone_july);
     }




More information about the wine-cvs mailing list