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 16, 2023
1 parent 35e773d commit 3143289
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions components/libc/compilers/common/ctime.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,16 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
tv->tv_usec = 0;

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

rt_set_errno(EINVAL);
Expand All @@ -498,7 +507,16 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
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)
{
return 0;
}
else
{
if (_control_rtc(RT_DEVICE_CTRL_RTC_SET_TIME, (void *)&tv->tv_sec) == RT_EOK)
{
return 0;
}
}
}

rt_set_errno(EINVAL);
Expand Down

0 comments on commit 3143289

Please sign in to comment.