diff options
Diffstat (limited to 'common/sys/time.c')
-rw-r--r-- | common/sys/time.c | 30 |
1 files changed, 18 insertions, 12 deletions
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; } |