You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by bt...@apache.org on 2020/07/20 02:35:30 UTC
[incubator-nuttx] 01/02: libc: Don't define localtime[_r] to macro
when CONFIG_LIBC_LOCALTIME not define
This is an automated email from the ASF dual-hosted git repository.
btashton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit e1ecb3e27c2bcc21be41980da1e7d89ea0365edc
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Thu Jul 16 12:09:54 2020 +0800
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 <xi...@xiaomi.com>
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 600d32c..ae5a209 100644
--- a/Documentation/NuttxUserGuide.html
+++ b/Documentation/NuttxUserGuide.html
@@ -4204,11 +4204,7 @@ Otherwise, an -1 (<code>ERROR</code>) will be returned and the <code>errno</code
<H3><a name="localtime">2.6.6 localtime</a></H3>
<ul><pre>
#include <time.h>
-#ifdef CONFIG_LIBC_LOCALTIME
-# define localtime(c) gmtime(c)
-#else
FAR struct tm *localtime(FAR const time_t *timep);
-#endif
</pre></ul>
<p>
<b>Description:</b>
@@ -4317,11 +4313,7 @@ FAR char *ctime(FAR const time_t *timep);
<H3><a name="localtimer">2.6.10 localtime_r</a></H3>
<ul><pre>
#include <time.h>
-#ifdef CONFIG_LIBC_LOCALTIME
-# define localtime_r(c,r) gmtime_r(c,r)
-#else
FAR struct tm *localtime_r(FAR const time_t *timep, FAR struct tm *result);
-#endif
</pre></ul>
<p>
<b>Description:</b>
diff --git a/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c b/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c
index 9fe1a90..04de05f 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 f6d7f1e..e04af7f 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 fa7b16d..c36018c 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 6171772..1a2f129 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 87ecd4d..14d85b8 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 11e56c8..e6dcf4b 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 47a7d26..50a6f75 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 2f7819c..e1bb321 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 77a07d0..8e095cf 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 8ef0b68..f594225 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 df189c0..65eeae5 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