diff options
| author | 马龙伟 <[email protected]> | 2024-08-04 09:56:47 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-08-04 09:56:47 +0800 |
| commit | 47cd52d162248eed0b8a5d6a1d04c870874ddae8 (patch) | |
| tree | bc862ff41012ab513a29ea6004648b225e5cd986 /components/libc/compilers/common | |
| parent | c9d4fd505963b138689c78e2c917004216dea3d9 (diff) | |
修复不使能 RT_USING_DEVICE 时编译报错 (#9145)
* 修复不使能 RT_USING_DEVICE 时编译报错
* 删除 ctime.c 中多余引用
Diffstat (limited to 'components/libc/compilers/common')
| -rw-r--r-- | components/libc/compilers/common/ctime.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/components/libc/compilers/common/ctime.c b/components/libc/compilers/common/ctime.c index ef006c4a1e..b523c827f9 100644 --- a/components/libc/compilers/common/ctime.c +++ b/components/libc/compilers/common/ctime.c @@ -30,8 +30,10 @@ #include "sys/time.h" #include <rthw.h> +#include <rtthread.h> +#ifdef RT_USING_RTC #include <rtdevice.h> -#include <drivers/rtc.h> +#endif /* RT_USING_RTC */ #include <sys/errno.h> #include <unistd.h> #ifdef RT_USING_SMART @@ -87,9 +89,9 @@ static void num2str(char *c, int i) c[1] = i % 10 + '0'; } +#ifdef RT_USING_RTC static rt_err_t _control_rtc(int cmd, void *arg) { -#ifdef RT_USING_RTC static rt_device_t device = RT_NULL; rt_err_t rst = -RT_ERROR; @@ -113,11 +115,8 @@ static rt_err_t _control_rtc(int cmd, void *arg) return -RT_ENOSYS; } return rst; -#else - LOG_W(_WARNING_NO_RTC); - return -RT_ENOSYS; -#endif /* RT_USING_RTC */ } +#endif /* RT_USING_RTC */ /* lightweight timezone and daylight saving time */ #ifdef RT_LIBC_USING_LIGHT_TZ_DST @@ -340,6 +339,7 @@ RTM_EXPORT(strftime); /* inherent in the toolchain */ */ rt_weak time_t time(time_t *t) { +#ifdef RT_USING_RTC time_t _t; if (_control_rtc(RT_DEVICE_CTRL_RTC_GET_TIME, &_t) != RT_EOK) @@ -352,6 +352,10 @@ rt_weak time_t time(time_t *t) *t = _t; return _t; +#else + rt_set_errno(EFAULT); + return (time_t)-1; +#endif } RTM_EXPORT(time); @@ -363,10 +367,12 @@ RTM_EXPORT(clock); int stime(const time_t *t) { +#ifdef RT_USING_RTC if ((t != RT_NULL) && (_control_rtc(RT_DEVICE_CTRL_RTC_SET_TIME, (void *)t) == RT_EOK)) { return 0; } +#endif /* RT_USING_RTC */ rt_set_errno(EFAULT); return -1; @@ -475,6 +481,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) #endif /* RT_LIBC_USING_LIGHT_TZ_DST */ } +#ifdef RT_USING_RTC if (tv != RT_NULL) { tv->tv_sec = 0; @@ -492,6 +499,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz) } } } +#endif /* RT_USING_RTC */ rt_set_errno(EINVAL); return -1; @@ -505,6 +513,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) * The tz_dsttime field has never been used under Linux. * Thus, the following is purely of historic interest. */ +#ifdef RT_USING_RTC 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) @@ -519,6 +528,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) } } } +#endif /* RT_USING_RTC */ rt_set_errno(EINVAL); return -1; |
