Skip to content

Commit 47cd52d

Browse files
authored
修复不使能 RT_USING_DEVICE 时编译报错 (#9145)
* 修复不使能 RT_USING_DEVICE 时编译报错 * 删除 ctime.c 中多余引用
1 parent c9d4fd5 commit 47cd52d

File tree

1 file changed

+16
-6
lines changed
  • components/libc/compilers/common

1 file changed

+16
-6
lines changed

components/libc/compilers/common/ctime.c

+16-6
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030

3131
#include "sys/time.h"
3232
#include <rthw.h>
33+
#include <rtthread.h>
34+
#ifdef RT_USING_RTC
3335
#include <rtdevice.h>
34-
#include <drivers/rtc.h>
36+
#endif /* RT_USING_RTC */
3537
#include <sys/errno.h>
3638
#include <unistd.h>
3739
#ifdef RT_USING_SMART
@@ -87,9 +89,9 @@ static void num2str(char *c, int i)
8789
c[1] = i % 10 + '0';
8890
}
8991

92+
#ifdef RT_USING_RTC
9093
static rt_err_t _control_rtc(int cmd, void *arg)
9194
{
92-
#ifdef RT_USING_RTC
9395
static rt_device_t device = RT_NULL;
9496
rt_err_t rst = -RT_ERROR;
9597

@@ -113,11 +115,8 @@ static rt_err_t _control_rtc(int cmd, void *arg)
113115
return -RT_ENOSYS;
114116
}
115117
return rst;
116-
#else
117-
LOG_W(_WARNING_NO_RTC);
118-
return -RT_ENOSYS;
119-
#endif /* RT_USING_RTC */
120118
}
119+
#endif /* RT_USING_RTC */
121120

122121
/* lightweight timezone and daylight saving time */
123122
#ifdef RT_LIBC_USING_LIGHT_TZ_DST
@@ -340,6 +339,7 @@ RTM_EXPORT(strftime); /* inherent in the toolchain */
340339
*/
341340
rt_weak time_t time(time_t *t)
342341
{
342+
#ifdef RT_USING_RTC
343343
time_t _t;
344344

345345
if (_control_rtc(RT_DEVICE_CTRL_RTC_GET_TIME, &_t) != RT_EOK)
@@ -352,6 +352,10 @@ rt_weak time_t time(time_t *t)
352352
*t = _t;
353353

354354
return _t;
355+
#else
356+
rt_set_errno(EFAULT);
357+
return (time_t)-1;
358+
#endif
355359
}
356360
RTM_EXPORT(time);
357361

@@ -363,10 +367,12 @@ RTM_EXPORT(clock);
363367

364368
int stime(const time_t *t)
365369
{
370+
#ifdef RT_USING_RTC
366371
if ((t != RT_NULL) && (_control_rtc(RT_DEVICE_CTRL_RTC_SET_TIME, (void *)t) == RT_EOK))
367372
{
368373
return 0;
369374
}
375+
#endif /* RT_USING_RTC */
370376

371377
rt_set_errno(EFAULT);
372378
return -1;
@@ -475,6 +481,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
475481
#endif /* RT_LIBC_USING_LIGHT_TZ_DST */
476482
}
477483

484+
#ifdef RT_USING_RTC
478485
if (tv != RT_NULL)
479486
{
480487
tv->tv_sec = 0;
@@ -492,6 +499,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
492499
}
493500
}
494501
}
502+
#endif /* RT_USING_RTC */
495503

496504
rt_set_errno(EINVAL);
497505
return -1;
@@ -505,6 +513,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
505513
* The tz_dsttime field has never been used under Linux.
506514
* Thus, the following is purely of historic interest.
507515
*/
516+
#ifdef RT_USING_RTC
508517
if (tv != RT_NULL && (long)tv->tv_usec >= 0 && (long)tv->tv_sec >= 0)
509518
{
510519
if (_control_rtc(RT_DEVICE_CTRL_RTC_SET_TIMEVAL, (void *)tv) == RT_EOK)
@@ -519,6 +528,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
519528
}
520529
}
521530
}
531+
#endif /* RT_USING_RTC */
522532

523533
rt_set_errno(EINVAL);
524534
return -1;

0 commit comments

Comments
 (0)