精简settimeofday代码;

在Linux中settimeofday以及gettimeofday函数的时区功能已经被废弃,因此增加注释予以提示。
gettimeofday实现了tz_minuteswest功能,tz_dsttime功能未实现,按废弃处理;
settimeofday时区功能废弃。
This commit is contained in:
Meco Man 2021-05-01 16:21:52 +08:00
parent 6fa385b987
commit 47de526525
1 changed files with 18 additions and 23 deletions

View File

@ -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 * @param tv: struct timeval
* @return the operation status, RT_EOK on successful * @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 #ifdef RT_USING_RTC
static rt_device_t device = RT_NULL; static rt_device_t device = RT_NULL;
@ -415,9 +415,13 @@ time_t timegm(struct tm * const t)
} }
RTM_EXPORT(timegm); RTM_EXPORT(timegm);
/* TODO: Daylight Saving Time */
int gettimeofday(struct timeval *tv, struct timezone *tz) 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) if(tz != RT_NULL)
{ {
tz->tz_dsttime = 0; tz->tz_dsttime = 0;
@ -436,32 +440,23 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
} }
RTM_EXPORT(gettimeofday); RTM_EXPORT(gettimeofday);
/* TODO: Daylight Saving Time */
int settimeofday(const struct timeval *tv, const struct timezone *tz) 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) return 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;
}
} }
else else
{ {
rt_set_errno(EFAULT); rt_set_errno(EINVAL);
return -1; return -1;
} }
} }