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 <xiaoxiang@xiaomi.com>
Change-Id: Ic0bb68b44c0cab838ab7cc34baee2aaa3ca8a9b5
This commit is contained in:
Xiang Xiao 2020-07-16 12:09:54 +08:00 committed by Brennan Ashton
parent 11f8b7c974
commit e1ecb3e27c
12 changed files with 19 additions and 70 deletions

View File

@ -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 &lt;time.h&gt;
#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 &lt;time.h&gt;
#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>

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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");
}

View File

@ -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 */

View File

@ -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. */

View File

@ -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 */

View File

@ -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);

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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