On Wed, Nov 12, 2014 at 12:24 AM, Ray Donnelly <mingw.andr...@gmail.com>
wrote:
> On Tue, Nov 11, 2014 at 2:02 PM, Dongsheng Song
> <dongsheng.s...@gmail.com> wrote:
>> I think you need add 1 line like this:
>>
>> TODO: real thread safe implementation.
>>
>
> Why? msvcrt is thread safe already.
>

MSDN not said asctime[1] is thread safe, it only said gmtime, mktime,
mkgmtime, and localtime [2] use one common tm structure per thread for the
conversion.

[1] http://msdn.microsoft.com/en-us/library/kys1801b.aspx
[2] http://msdn.microsoft.com/en-us/library/0z9czt0w.aspx

Then you can not assume asctime is thread safe.

*) typo

+char *__cdecl asctime(const struct tm *_Tm, char * _Str)
+{
+    char *tmp = asctime(_Tm);
+    if (tmp)
+        tmp = strcpy(_Str,tmp);
+    return tmp;
+}

should changed to:

+ /* TODO: thread safe implementation */
+char *__cdecl asctime_r(const struct tm *_Tm, char * _Str)
+{
+    char *tmp;
+
+    if (_Tm == NULL || _Str == NULL)
+    {
+        errno = EINVAL;
+        return NULL;

+    }
+
+    tmp = asctime(_Tm);
+    if (tmp != NULL)
+        tmp = strcpy(_Str,tmp);
+
+    return tmp;
+}

*) bad structure copy

+struct tm *__cdecl localtime_r(const time_t *_Time, struct tm *_Tm)
+{
+    struct tm *tmp = localtime(_Time);
+    if (tmp)
+        *_Tm = *tmp;
+    return tmp;
​​

​​
+}

should changed to:

+ /* Both the 32-bit and 64-bit versions of gmtime, mktime, mkgmtime,
+  * and localtime all use one common tm structure per thread for the
+  * 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)
+        memcpy(_Tm, tmp, sizeof(struct tm);
+    return tmp;
​​
​+}​
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to