Commit 0703dba1 authored by heikki@donna.mysql.fi's avatar heikki@donna.mysql.fi

ut0ut.c Rewrote ut_print_timestamp with localtime_r and in Win GetLocalTime

parent 125b4bd6
...@@ -57,25 +57,26 @@ ut_print_timestamp( ...@@ -57,25 +57,26 @@ ut_print_timestamp(
/*===============*/ /*===============*/
FILE* file) /* in: file where to print */ FILE* file) /* in: file where to print */
{ {
struct tm* cal_tm_ptr; #ifdef __WIN__
struct tm cal_tm; SYSTEMTIME cal_tm;
time_t tm;
try_again: GetLocalTime(&cal_tm);
time(&tm);
cal_tm_ptr = localtime(&tm); fprintf(file,"%02d%02d%02d %2d:%02d:%02d",
(int)cal_tm.wYear % 100,
memcpy(&cal_tm, cal_tm_ptr, sizeof(struct tm)); (int)cal_tm.wMonth,
(int)cal_tm.wDay,
(int)cal_tm.wHour,
(int)cal_tm.wMinute,
(int)cal_tm.wSecond);
#else
/* In theory localtime may return a wrong result because its return struct tm cal_tm;
struct is not protected with a mutex */ time_t tm;
if (difftime(tm, mktime(&cal_tm)) > 0.5 time(&tm);
|| difftime(tm, mktime(&cal_tm)) < -0.5) {
goto try_again; localtime_r(&tm, &cal_tm);
}
fprintf(file,"%02d%02d%02d %2d:%02d:%02d", fprintf(file,"%02d%02d%02d %2d:%02d:%02d",
cal_tm.tm_year % 100, cal_tm.tm_year % 100,
...@@ -84,6 +85,7 @@ ut_print_timestamp( ...@@ -84,6 +85,7 @@ ut_print_timestamp(
cal_tm.tm_hour, cal_tm.tm_hour,
cal_tm.tm_min, cal_tm.tm_min,
cal_tm.tm_sec); cal_tm.tm_sec);
#endif
} }
/***************************************************************** /*****************************************************************
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment