From 1f0b3cd9795e2979fc3c4454d4fbcf74c65298e0 Mon Sep 17 00:00:00 2001 From: piaip Date: Mon, 5 May 2008 02:50:55 +0000 Subject: - (internal) change localtime() to localtime_r() API. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4270 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- common/sys/time.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'common') diff --git a/common/sys/time.c b/common/sys/time.c index bf8164c9..7cf963b3 100644 --- a/common/sys/time.c +++ b/common/sys/time.c @@ -43,9 +43,10 @@ const char* Cdate(const time4_t *clock) { time_t temp = (time_t)*clock; - struct tm *mytm = localtime(&temp); + struct tm mytm; - strftime(cdate_buffer, sizeof(cdate_buffer), "%m/%d/%Y %T %a", mytm); + localtime_r(&temp, &mytm); + strftime(cdate_buffer, sizeof(cdate_buffer), "%m/%d/%Y %T %a", &mytm); return cdate_buffer; } @@ -56,9 +57,10 @@ const char* Cdatelite(const time4_t *clock) { time_t temp = (time_t)*clock; - struct tm *mytm = localtime(&temp); + struct tm mytm; - strftime(cdate_buffer, sizeof(cdate_buffer), "%m/%d/%Y %T", mytm); + localtime_r(&temp, &mytm); + strftime(cdate_buffer, sizeof(cdate_buffer), "%m/%d/%Y %T", &mytm); return cdate_buffer; } @@ -69,9 +71,10 @@ const char* Cdatedate(const time4_t * clock) { time_t temp = (time_t)*clock; - struct tm *mytm = localtime(&temp); + struct tm mytm; - strftime(cdate_buffer, sizeof(cdate_buffer), "%m/%d/%Y", mytm); + localtime_r(&temp, &mytm); + strftime(cdate_buffer, sizeof(cdate_buffer), "%m/%d/%Y", &mytm); return cdate_buffer; } @@ -82,9 +85,10 @@ const char* Cdate_mdHM(const time4_t * clock) { time_t temp = (time_t)*clock; - struct tm *mytm = localtime(&temp); + struct tm mytm; - strftime(cdate_buffer, sizeof(cdate_buffer), "%m/%d %H:%M", mytm); + localtime_r(&temp, &mytm); + strftime(cdate_buffer, sizeof(cdate_buffer), "%m/%d %H:%M", &mytm); return cdate_buffer; } @@ -97,6 +101,7 @@ ctime4(const time4_t *clock) return ctime(&temp); } +// XXX TODO change this to localtime_r style someday. struct tm *localtime4(const time4_t *t) { if( t == NULL ) @@ -119,11 +124,12 @@ time4_t time4(time4_t *ptr) const char* my_ctime(const time4_t * t, char *ans, int len) { - struct tm *tp; + time_t temp = (time_t)*clock; + struct tm tp; - tp = localtime4((time4_t*)t); + localtime_r(&temp, &tp); snprintf(ans, len, - "%02d/%02d/%02d %02d:%02d:%02d", (tp->tm_year % 100), - tp->tm_mon + 1, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec); + "%02d/%02d/%02d %02d:%02d:%02d", (tp.tm_year % 100), + tp.tm_mon + 1, tp.tm_mday, tp.tm_hour, tp.tm_min, tp.tm_sec); return ans; } -- cgit v1.2.3