summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-05-05 10:50:55 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2008-05-05 10:50:55 +0800
commit1f0b3cd9795e2979fc3c4454d4fbcf74c65298e0 (patch)
tree44721dab90b6e829a60227dbedbe1693b861eb9a
parent69c9cb0679788ad922528ae140249a1c0ba88da7 (diff)
downloadpttbbs-1f0b3cd9795e2979fc3c4454d4fbcf74c65298e0.tar
pttbbs-1f0b3cd9795e2979fc3c4454d4fbcf74c65298e0.tar.gz
pttbbs-1f0b3cd9795e2979fc3c4454d4fbcf74c65298e0.tar.bz2
pttbbs-1f0b3cd9795e2979fc3c4454d4fbcf74c65298e0.tar.lz
pttbbs-1f0b3cd9795e2979fc3c4454d4fbcf74c65298e0.tar.xz
pttbbs-1f0b3cd9795e2979fc3c4454d4fbcf74c65298e0.tar.zst
pttbbs-1f0b3cd9795e2979fc3c4454d4fbcf74c65298e0.zip
- (internal) change localtime() to localtime_r() API.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4270 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r--common/sys/time.c30
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;
}