From e1ecb3e27c2bcc21be41980da1e7d89ea0365edc Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Thu, 16 Jul 2020 12:09:54 +0800 Subject: [PATCH] libc: Don't define localtime[_r] to macro when CONFIG_LIBC_LOCALTIME not define since libc++ declare these function in ctime by: using ::localtime[_r]; Signed-off-by: Xiang Xiao Change-Id: Ic0bb68b44c0cab838ab7cc34baee2aaa3ca8a9b5 --- Documentation/NuttxUserGuide.html | 8 -------- arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c | 5 ----- arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c | 4 ---- arch/renesas/src/rx65n/rx65n_rtc.c | 6 +----- drivers/timers/ds3231.c | 9 --------- drivers/timers/mcp794xx.c | 9 --------- drivers/timers/pcf85263.c | 9 --------- include/time.h | 9 --------- libs/libc/time/lib_ctime.c | 4 ---- libs/libc/time/lib_ctimer.c | 4 ---- libs/libc/time/lib_gmtime.c | 11 +++++++++-- libs/libc/time/lib_gmtimer.c | 11 +++++++++-- 12 files changed, 19 insertions(+), 70 deletions(-) diff --git a/Documentation/NuttxUserGuide.html b/Documentation/NuttxUserGuide.html index 600d32cc31f..ae5a2094d10 100644 --- a/Documentation/NuttxUserGuide.html +++ b/Documentation/NuttxUserGuide.html @@ -4204,11 +4204,7 @@ Otherwise, an -1 (ERROR) will be returned and the errno2.6.6 localtime

Description: @@ -4317,11 +4313,7 @@ FAR char *ctime(FAR const time_t *timep);

2.6.10 localtime_r

Description: diff --git a/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c b/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c index 9fe1a9061f6..04de05fd966 100644 --- a/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c +++ b/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c @@ -531,13 +531,8 @@ static int kinetis_rdalarm(FAR struct rtc_lowerhalf_s *lower, sched_lock(); ret = kinetis_rtc_rdalarm(&ts); -#ifdef CONFIG_LIBC_LOCALTIME localtime_r((FAR const time_t *)&ts.tv_sec, (FAR struct tm *)alarminfo->time); -#else - gmtime_r((FAR const time_t *)&ts.tv_sec, - (FAR struct tm *)alarminfo->time); -#endif sched_unlock(); } diff --git a/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c b/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c index f6d7f1ed4e7..e04af7fa74e 100644 --- a/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c +++ b/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c @@ -602,11 +602,7 @@ static int max326_rdalarm(FAR struct rtc_lowerhalf_s *lower, /* Convert to struct rtc_time (aka struct tm) */ -#ifdef CONFIG_LIBC_LOCALTIME localtime_r(&sec, (FAR struct tm *)alarminfo->time); -#else - gmtime_r(&sec, (FAR struct tm *)alarminfo->time); -#endif ret = OK; } } diff --git a/arch/renesas/src/rx65n/rx65n_rtc.c b/arch/renesas/src/rx65n/rx65n_rtc.c index fa7b16da545..c36018cac25 100644 --- a/arch/renesas/src/rx65n/rx65n_rtc.c +++ b/arch/renesas/src/rx65n/rx65n_rtc.c @@ -774,7 +774,6 @@ int up_rtc_settime(FAR const struct timespec *tp) /* Day of the week (0-6, 0=Sunday) */ -#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) RTC.RWKCNT.BYTE = rtc_dec2bcd((uint8_t) newtime.tm_wday); /* WAIT_LOOP */ @@ -783,7 +782,6 @@ int up_rtc_settime(FAR const struct timespec *tp) { dummy_byte = RTC.RWKCNT.BYTE; } -#endif /* Day of the month (1-31) */ @@ -1355,9 +1353,7 @@ int up_rtc_getdatetime(FAR struct tm *tp) /* Days since Sunday (0-6) */ -#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) - tp->tm_wday = (int) (RTC.RWKCNT.BYTE & 0x07u); -#endif + tp->tm_wday = (int) (RTC.RWKCNT.BYTE & 0x07u); rtc_dumptime(tp, "Returning"); } diff --git a/drivers/timers/ds3231.c b/drivers/timers/ds3231.c index 6171772c920..1a2f1294edd 100644 --- a/drivers/timers/ds3231.c +++ b/drivers/timers/ds3231.c @@ -425,21 +425,12 @@ int up_rtc_settime(FAR const struct timespec *tp) newtime++; } -#ifdef CONFIG_LIBC_LOCALTIME if (localtime_r(&newtime, &newtm) == NULL) { rtcerr("ERROR: localtime_r failed\n"); return -EINVAL; } -#else - if (gmtime_r(&newtime, &newtm) == NULL) - { - rtcerr("ERROR: gmtime_r failed\n"); - return -EINVAL; - } -#endif - rtc_dumptime(&newtm, "New time"); /* Construct the message */ diff --git a/drivers/timers/mcp794xx.c b/drivers/timers/mcp794xx.c index 87ecd4d1334..14d85b85edb 100644 --- a/drivers/timers/mcp794xx.c +++ b/drivers/timers/mcp794xx.c @@ -426,21 +426,12 @@ int up_rtc_settime(FAR const struct timespec *tp) newtime++; } -#ifdef CONFIG_LIBC_LOCALTIME if (localtime_r(&newtime, &newtm) == NULL) { rtcerr("ERROR: localtime_r failed\n"); return -EINVAL; } -#else - if (gmtime_r(&newtime, &newtm) == NULL) - { - rtcerr("ERROR: gmtime_r failed\n"); - return -EINVAL; - } -#endif - rtc_dumptime(&newtm, "New time"); /* Stop the oscillator first. */ diff --git a/drivers/timers/pcf85263.c b/drivers/timers/pcf85263.c index 11e56c8a1e1..e6dcf4b56b3 100644 --- a/drivers/timers/pcf85263.c +++ b/drivers/timers/pcf85263.c @@ -408,21 +408,12 @@ int up_rtc_settime(FAR const struct timespec *tp) newtime++; } -#ifdef CONFIG_LIBC_LOCALTIME if (localtime_r(&newtime, &newtm) == NULL) { rtcerr("ERROR: localtime_r failed\n") return -EINVAL; } -#else - if (gmtime_r(&newtime, &newtm) == NULL) - { - rtcerr("ERROR: gmtime_r failed\n") - return -EINVAL; - } -#endif - rtc_dumptime(&tm, "New time"); /* Construct the message */ diff --git a/include/time.h b/include/time.h index 47a7d26968f..50a6f75eaec 100644 --- a/include/time.h +++ b/include/time.h @@ -100,13 +100,6 @@ #define TIME_UTC 1 -#ifndef CONFIG_LIBC_LOCALTIME -/* Local time is the same as gmtime in this implementation */ - -# define localtime(c) gmtime(c) -# define localtime_r(c,r) gmtime_r(c,r) -#endif - /******************************************************************************** * Public Types ********************************************************************************/ @@ -206,10 +199,8 @@ time_t mktime(FAR struct tm *tp); FAR struct tm *gmtime(FAR const time_t *timep); FAR struct tm *gmtime_r(FAR const time_t *timep, FAR struct tm *result); -#ifdef CONFIG_LIBC_LOCALTIME FAR struct tm *localtime(FAR const time_t *timep); FAR struct tm *localtime_r(FAR const time_t *timep, FAR struct tm *result); -#endif size_t strftime(FAR char *s, size_t max, FAR const char *format, FAR const struct tm *tm); diff --git a/libs/libc/time/lib_ctime.c b/libs/libc/time/lib_ctime.c index 2f7819cdc30..e1bb321599a 100644 --- a/libs/libc/time/lib_ctime.c +++ b/libs/libc/time/lib_ctime.c @@ -64,7 +64,6 @@ FAR char *ctime(FAR const time_t *timep) { -#ifdef CONFIG_LIBC_LOCALTIME /* Section 4.12.3.2 of X3.159-1989 requires that * The ctime function converts the calendar time pointed to by timer * to local time in the form of a string. It is equivalent to @@ -72,7 +71,4 @@ FAR char *ctime(FAR const time_t *timep) */ return asctime(localtime(timep)); -#else - return asctime(gmtime(timep)); -#endif } diff --git a/libs/libc/time/lib_ctimer.c b/libs/libc/time/lib_ctimer.c index 77a07d097a7..8e095cfcabb 100644 --- a/libs/libc/time/lib_ctimer.c +++ b/libs/libc/time/lib_ctimer.c @@ -71,9 +71,5 @@ FAR char *ctime_r(FAR const time_t *timep, FAR char *buf) { struct tm tm; -#ifdef CONFIG_LIBC_LOCALTIME return asctime_r(localtime_r(timep, &tm), buf); -#else - return asctime_r(gmtime_r(timep, &tm), buf); -#endif } diff --git a/libs/libc/time/lib_gmtime.c b/libs/libc/time/lib_gmtime.c index 8ef0b68707e..f59422541ca 100644 --- a/libs/libc/time/lib_gmtime.c +++ b/libs/libc/time/lib_gmtime.c @@ -57,8 +57,15 @@ * ****************************************************************************/ -struct tm *gmtime(const time_t *timer) +FAR struct tm *gmtime(FAR const time_t *timep) { static struct tm tm; - return gmtime_r(timer, &tm); + return gmtime_r(timep, &tm); } + +#ifndef CONFIG_LIBC_LOCALTIME +FAR struct tm *localtime(FAR const time_t *timep) +{ + return gmtime(timep); +} +#endif diff --git a/libs/libc/time/lib_gmtimer.c b/libs/libc/time/lib_gmtimer.c index df189c0407f..65eeae599a4 100644 --- a/libs/libc/time/lib_gmtimer.c +++ b/libs/libc/time/lib_gmtimer.c @@ -301,7 +301,7 @@ static void clock_utc2calendar(time_t days, FAR int *year, FAR int *month, * ****************************************************************************/ -FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result) +FAR struct tm *gmtime_r(FAR const time_t *timep, FAR struct tm *result) { time_t epoch; time_t jdn; @@ -314,7 +314,7 @@ FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result) /* Get the seconds since the EPOCH */ - epoch = *timer; + epoch = *timep; linfo("timer=%d\n", (int)epoch); /* Convert to days, hours, minutes, and seconds since the EPOCH */ @@ -357,3 +357,10 @@ FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result) return result; } + +#ifndef CONFIG_LIBC_LOCALTIME +FAR struct tm *localtime_r(FAR const time_t *timep, FAR struct tm *result) +{ + return gmtime_r(timep, result); +} +#endif