[libc] update ctime.c compatible with old drivers

This commit is contained in:
guozhanxin 2023-11-14 18:18:07 +08:00 committed by guo
parent 35e773d46a
commit 3143289486
1 changed files with 18 additions and 0 deletions

View File

@ -480,8 +480,17 @@ 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);
return -1;
@ -498,8 +507,17 @@ 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);
return -1;