From a314d266f32a660494dd387cda93db59c06dd68c Mon Sep 17 00:00:00 2001 From: emlsyx Date: Thu, 4 Feb 2021 16:30:15 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E8=B0=83=E7=94=A8=20asctime?= =?UTF-8?q?=5Fr=E6=97=B6=20=E5=86=85=E5=AD=98=E6=BA=A2=E5=87=BA=E7=9A=84bu?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 33 +++++++++++++------------ 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 99dab71eb4..f6f35acb5f 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -81,25 +81,25 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r) return r; } -struct tm* gmtime(const time_t* t) +struct tm *gmtime(const time_t *t) { static struct tm tmp; return gmtime_r(t, &tmp); } /*TODO timezone is not supprt now */ -struct tm* localtime_r(const time_t* t, struct tm* r) +struct tm *localtime_r(const time_t *t, struct tm *r) { return gmtime_r(t, r); } -struct tm* localtime(const time_t* t) +struct tm *localtime(const time_t *t) { static struct tm tmp; return localtime_r(t, &tmp); } -time_t mktime(struct tm * const t) +time_t mktime(struct tm *const t) { register time_t day; register time_t i; @@ -179,11 +179,12 @@ static void num2str(char *c, int i) c[1] = i % 10 + '0'; } -char* asctime_r(const struct tm *t, char *buf) +char *asctime_r(const struct tm *t, char *buf) { /* "Wed Jun 30 21:49:08 1993\n" */ - *(int*) buf = *(int*) (days + (t->tm_wday << 2)); - *(int*) (buf + 4) = *(int*) (months + (t->tm_mon << 2)); + rt_memcpy(buf, (days + (t->tm_wday << 2)), 4); + rt_memcpy((buf + 4), (months + (t->tm_mon << 2)), 4); + num2str(buf + 8, t->tm_mday); if (buf[8] == '0') buf[8] = ' '; @@ -200,13 +201,13 @@ char* asctime_r(const struct tm *t, char *buf) return buf; } -char* asctime(const struct tm *timeptr) +char *asctime(const struct tm *timeptr) { static char buf[25]; return asctime_r(timeptr, buf); } -char* ctime(const time_t *timep) +char *ctime(const time_t *timep) { return asctime(localtime(timep)); } @@ -245,14 +246,14 @@ int gettimeofday(struct timeval *tp, void *ignore) */ /* for IAR 6.2 later Compiler */ #if defined (__IAR_SYSTEMS_ICC__) && (__VER__) >= 6020000 -#pragma module_name = "?time" -#if _DLIB_TIME_USES_64 -time_t __time64(time_t *t) -#else -time_t __time32(time_t *t) -#endif + #pragma module_name = "?time" + #if _DLIB_TIME_USES_64 + time_t __time64(time_t *t) + #else + time_t __time32(time_t *t) + #endif #else -time_t time(time_t *t) + time_t time(time_t *t) #endif { time_t time_now = 0; -- Gitee