From 47de5265250f76ed1f48f7d1c51beda690a4bd74 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 1 May 2021 16:21:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E7=AE=80settimeofday=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=9B=20=E5=9C=A8Linux=E4=B8=ADsettimeofday?= =?UTF-8?q?=E4=BB=A5=E5=8F=8Agettimeofday=E5=87=BD=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=8C=BA=E5=8A=9F=E8=83=BD=E5=B7=B2=E7=BB=8F=E8=A2=AB?= =?UTF-8?q?=E5=BA=9F=E5=BC=83=EF=BC=8C=E5=9B=A0=E6=AD=A4=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E4=BA=88=E4=BB=A5=E6=8F=90=E7=A4=BA=E3=80=82?= =?UTF-8?q?=20gettimeofday=E5=AE=9E=E7=8E=B0=E4=BA=86tz=5Fminuteswest?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8Ctz=5Fdsttime=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=9C=AA=E5=AE=9E=E7=8E=B0=EF=BC=8C=E6=8C=89=E5=BA=9F=E5=BC=83?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=9B=20settimeofday=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=BA=9F=E5=BC=83=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 41 +++++++++++-------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 388dc52ac3..50fbe0d5cc 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -124,11 +124,11 @@ static rt_err_t get_timeval(struct timeval *tv) } /** - * Set time to RTC device (without timezone, UTC+0) + * Set time to RTC device (without timezone) * @param tv: struct timeval * @return the operation status, RT_EOK on successful */ -static rt_err_t set_timeval(struct timeval *tv) +static int set_timeval(const struct timeval *tv) { #ifdef RT_USING_RTC static rt_device_t device = RT_NULL; @@ -415,9 +415,13 @@ time_t timegm(struct tm * const t) } RTM_EXPORT(timegm); -/* TODO: Daylight Saving Time */ int gettimeofday(struct timeval *tv, struct timezone *tz) { + /* The use of the timezone structure is obsolete; + * the tz argument should normally be specified as NULL. + * The tz_dsttime field has never been used under Linux. + * Thus, the following is purely of historic interest. + */ if(tz != RT_NULL) { tz->tz_dsttime = 0; @@ -436,32 +440,23 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) } RTM_EXPORT(gettimeofday); -/* TODO: Daylight Saving Time */ int settimeofday(const struct timeval *tv, const struct timezone *tz) { - if (tv != RT_NULL) + /* The use of the timezone structure is obsolete; + * the tz argument should normally be specified as NULL. + * The tz_dsttime field has never been used under Linux. + * Thus, the following is purely of historic interest. + */ + if (tv != RT_NULL + && tv->tv_sec >= 0 + && tv->tv_usec >= 0 + && set_timeval(tv) == RT_EOK) { - if(tv->tv_sec >= 0 && tv->tv_usec >= 0) - { - if(set_timeval((struct timeval *)tv) == RT_EOK) - { - return 0; - } - else - { - rt_set_errno(EFAULT); - return -1; - } - } - else - { - rt_set_errno(EINVAL); - return -1; - } + return 0; } else { - rt_set_errno(EFAULT); + rt_set_errno(EINVAL); return -1; } } -- GitLab