Skip to content

Commit

Permalink
[libc] update ctime.c compatible with old drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
Guozhanxin committed Nov 15, 2023
1 parent 6d7e393 commit c0e8ec1
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions components/libc/compilers/common/ctime.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ RTM_EXPORT(timegm);

int gettimeofday(struct timeval *tv, struct timezone *tz)
{
rt_err_t ret;
/* 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.
Expand All @@ -478,9 +479,16 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
{
tv->tv_sec = 0;
tv->tv_usec = 0;

if (_control_rtc(RT_DEVICE_CTRL_RTC_GET_TIMEVAL, tv) == RT_EOK)
ret = _control_rtc(RT_DEVICE_CTRL_RTC_GET_TIMEVAL, tv);
if (ret == RT_EOK)
{
return 0;
}
else if (ret == -RT_EINVAL) /* RT_DEVICE_CTRL_RTC_GET_TIMEVAL */
{
ret = _control_rtc(RT_DEVICE_CTRL_RTC_GET_TIME, (void *)&tv->tv_sec);
}
return 0;
}

rt_set_errno(EINVAL);
Expand All @@ -490,15 +498,23 @@ RTM_EXPORT(gettimeofday);

int settimeofday(const struct timeval *tv, const struct timezone *tz)
{
rt_err_t ret;
/* 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 && (long)tv->tv_usec >= 0 && (long)tv->tv_sec >= 0)
{
if (_control_rtc(RT_DEVICE_CTRL_RTC_SET_TIMEVAL, (void *)tv) == RT_EOK)
ret = _control_rtc(RT_DEVICE_CTRL_RTC_SET_TIMEVAL, (void *)tv);
if (ret == RT_EOK)
{
return 0;
}
else if (ret == -RT_EINVAL) /* RT_DEVICE_CTRL_RTC_SET_TIME */
{
ret = _control_rtc(RT_DEVICE_CTRL_RTC_SET_TIME, (void *)&tv->tv_sec);
}
}

rt_set_errno(EINVAL);
Expand Down

0 comments on commit c0e8ec1

Please sign in to comment.