You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2021/06/23 16:44:07 UTC
[incubator-nuttx] 02/02: Replace mktime with timegm in rtc and fs
driver
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit ae9b5fd306181da9f05894425e89f2c8772b2e74
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Tue Jun 22 00:44:48 2021 +0800
Replace mktime with timegm in rtc and fs driver
since kernel component should use UTC instead local time
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
Change-Id: Icf939e1ab0af8e577105f539d2553bc67b3b3d10
---
arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c | 4 ++--
arch/arm/src/imxrt/imxrt_rtc_lowerhalf.c | 4 ++--
arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c | 6 +++---
arch/arm/src/lc823450/lc823450_rtc.c | 4 ++--
arch/arm/src/lpc54xx/lpc54_rtc_lowerhalf.c | 4 ++--
arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c | 6 +++---
arch/arm/src/sam34/sam_rtc.c | 2 +-
arch/arm/src/stm32/stm32_rtc_lowerhalf.c | 8 ++++----
arch/arm/src/stm32f7/stm32_rtc_lowerhalf.c | 4 ++--
arch/arm/src/stm32h7/stm32_rtc_lowerhalf.c | 4 ++--
arch/arm/src/stm32l4/stm32l4_rtc_lowerhalf.c | 2 +-
arch/renesas/src/rx65n/rx65n_rtc.c | 2 +-
arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c | 6 +++---
arch/sim/src/sim/up_rtc.c | 2 +-
arch/z80/src/ez80/ez80_rtc_lowerhalf.c | 4 ++--
drivers/timers/arch_rtc.c | 4 ++--
drivers/timers/rpmsg_rtc.c | 6 +++---
fs/fat/fs_fat32util.c | 2 +-
include/time.h | 1 -
sched/clock/clock_initialize.c | 2 +-
20 files changed, 38 insertions(+), 39 deletions(-)
diff --git a/arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c b/arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c
index 5ff9994..20df0d7 100644
--- a/arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c
+++ b/arch/arm/src/cxd56xx/cxd56_rtc_lowerhalf.c
@@ -270,7 +270,7 @@ static int cxd56_settime(FAR struct rtc_lowerhalf_s *lower,
* rtc_time is cast compatible with struct tm.
*/
- ts.tv_sec = mktime((FAR struct tm *)rtctime);
+ ts.tv_sec = timegm((FAR struct tm *)rtctime);
ts.tv_nsec = 0;
/* Now set the time (to one second accuracy) */
@@ -325,7 +325,7 @@ static int cxd56_setalarm(FAR struct rtc_lowerhalf_s *lower,
/* Convert the RTC time to a timespec (1 second accuracy) */
- lowerinfo.as_time.tv_sec = mktime((FAR struct tm *)&alarminfo->time);
+ lowerinfo.as_time.tv_sec = timegm((FAR struct tm *)&alarminfo->time);
lowerinfo.as_time.tv_nsec = 0;
/* And set the alarm */
diff --git a/arch/arm/src/imxrt/imxrt_rtc_lowerhalf.c b/arch/arm/src/imxrt/imxrt_rtc_lowerhalf.c
index 079ce0c..0712e62 100644
--- a/arch/arm/src/imxrt/imxrt_rtc_lowerhalf.c
+++ b/arch/arm/src/imxrt/imxrt_rtc_lowerhalf.c
@@ -238,7 +238,7 @@ static int imxrt_settime(FAR struct rtc_lowerhalf_s *lower,
* rtc_time is cast compatible with struct tm.
*/
- ts.tv_sec = mktime((FAR struct tm *)rtctime);
+ ts.tv_sec = timegm((FAR struct tm *)rtctime);
ts.tv_nsec = 0;
/* Now set the time (to one second accuracy) */
@@ -312,7 +312,7 @@ static int imxrt_setalarm(FAR struct rtc_lowerhalf_s *lower,
/* Convert the RTC time to a timespec (1 second accuracy) */
- ts.tv_sec = mktime((FAR struct tm *)&alarminfo->time);
+ ts.tv_sec = timegm((FAR struct tm *)&alarminfo->time);
ts.tv_nsec = 0;
/* Remember the callback information */
diff --git a/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c b/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c
index dbbad80..2c9702f 100644
--- a/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c
+++ b/arch/arm/src/kinetis/kinetis_rtc_lowerhalf.c
@@ -274,7 +274,7 @@ static int kinetis_settime(FAR struct rtc_lowerhalf_s *lower,
* rtc_time is cast compatible with struct tm.
*/
- ts.tv_sec = mktime((FAR struct tm *)rtctime);
+ ts.tv_sec = timegm((FAR struct tm *)rtctime);
ts.tv_nsec = 0;
/* Set the time (to one second accuracy) */
@@ -325,7 +325,7 @@ static int kinetis_setalarm(FAR struct rtc_lowerhalf_s *lower,
/* Convert from Julian calendar time to epoch time */
- tp.tv_sec = mktime((FAR struct tm *)&alarminfo->time) ;
+ tp.tv_sec = timegm((FAR struct tm *)&alarminfo->time) ;
/* And set the alarm */
@@ -393,7 +393,7 @@ kinetis_setrelative(FAR struct rtc_lowerhalf_s *lower,
return ret;
}
- ts.tv_sec = mktime(&time);
+ ts.tv_sec = timegm(&time);
ts.tv_nsec = 0;
#else
/* Get the current time in broken out format */
diff --git a/arch/arm/src/lc823450/lc823450_rtc.c b/arch/arm/src/lc823450/lc823450_rtc.c
index 03a0c89..b5a4952 100644
--- a/arch/arm/src/lc823450/lc823450_rtc.c
+++ b/arch/arm/src/lc823450/lc823450_rtc.c
@@ -170,7 +170,7 @@ volatile bool g_rtc_enabled = false;
static void tm_divider(struct tm *tm, int divn, int divm)
{
time_t tt;
- tt = mktime(tm);
+ tt = timegm(tm);
tt = (time_t) ((uint64_t)tt * divn / divm);
gmtime_r(&tt, tm);
}
@@ -690,7 +690,7 @@ int up_rtc_getrawtime(FAR struct timespec *ts)
#endif /* CONFIG_RTC_DIV */
ts->tv_nsec = 0;
- ts->tv_sec = mktime(&tm);
+ ts->tv_sec = timegm(&tm);
return 0;
}
diff --git a/arch/arm/src/lpc54xx/lpc54_rtc_lowerhalf.c b/arch/arm/src/lpc54xx/lpc54_rtc_lowerhalf.c
index e0779d11..3056d82 100644
--- a/arch/arm/src/lpc54xx/lpc54_rtc_lowerhalf.c
+++ b/arch/arm/src/lpc54xx/lpc54_rtc_lowerhalf.c
@@ -253,7 +253,7 @@ static int lpc54_settime(FAR struct rtc_lowerhalf_s *lower,
* rtc_time is cast compatible with struct tm.
*/
- ts.tv_sec = mktime((FAR struct tm *)rtctime);
+ ts.tv_sec = timegm((FAR struct tm *)rtctime);
ts.tv_nsec = 0;
/* Now set the time (to one second accuracy) */
@@ -321,7 +321,7 @@ static int lpc54_setalarm(FAR struct rtc_lowerhalf_s *lower,
/* Convert the RTC time to a timespec (1 second accuracy) */
- ts.tv_sec = mktime((FAR struct tm *)&alarminfo->time);
+ ts.tv_sec = timegm((FAR struct tm *)&alarminfo->time);
ts.tv_nsec = 0;
/* Remember the callback information */
diff --git a/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c b/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c
index 7d0152b..2489e59 100644
--- a/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c
+++ b/arch/arm/src/max326xx/common/max326_rtc_lowerhalf.c
@@ -314,7 +314,7 @@ static int max326_settime(FAR struct rtc_lowerhalf_s *lower,
* rtc_time is cast compatible with struct tm.
*/
- ts.tv_sec = mktime((FAR struct tm *)rtctime);
+ ts.tv_sec = timegm((FAR struct tm *)rtctime);
ts.tv_nsec = 0;
/* Now set the time (to one second accuracy) */
@@ -383,7 +383,7 @@ static int max326_setalarm(FAR struct rtc_lowerhalf_s *lower,
/* Convert the RTC time to a timespec (1 second accuracy) */
- ts.tv_sec = mktime((FAR struct tm *)&alarminfo->time);
+ ts.tv_sec = timegm((FAR struct tm *)&alarminfo->time);
ts.tv_nsec = 0;
/* Remember the callback information */
@@ -460,7 +460,7 @@ static int max326_setrelative(FAR struct rtc_lowerhalf_s *lower,
return ret;
}
- ts.tv_sec = mktime(&time);
+ ts.tv_sec = timegm(&time);
ts.tv_nsec = 0;
#elif defined(CONFIG_RTC_HIRES)
diff --git a/arch/arm/src/sam34/sam_rtc.c b/arch/arm/src/sam34/sam_rtc.c
index 858ca90..d3a622f 100644
--- a/arch/arm/src/sam34/sam_rtc.c
+++ b/arch/arm/src/sam34/sam_rtc.c
@@ -788,7 +788,7 @@ int up_rtc_gettime(FAR struct timespec *tp)
RTC_CALR_YEAR_SHIFT)
- 1900;
- tp->tv_sec = mktime(&t);
+ tp->tv_sec = timegm(&t);
tp->tv_nsec = (((rtt_val - g_rtt_offset) & (CONFIG_RTC_FREQUENCY - 1)) *
1000000000ull) / CONFIG_RTC_FREQUENCY;
diff --git a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
index ff01446..9b3ed1c 100644
--- a/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
+++ b/arch/arm/src/stm32/stm32_rtc_lowerhalf.c
@@ -347,7 +347,7 @@ static int stm32_settime(FAR struct rtc_lowerhalf_s *lower,
* rtc_time is cast compatible with struct tm.
*/
- ts.tv_sec = mktime((FAR struct tm *)rtctime);
+ ts.tv_sec = timegm((FAR struct tm *)rtctime);
ts.tv_nsec = 0;
/* Now set the time (to one second accuracy) */
@@ -470,7 +470,7 @@ static int stm32_setalarm(FAR struct rtc_lowerhalf_s *lower,
/* Convert the RTC time to a timespec (1 second accuracy) */
- ts.tv_sec = mktime((FAR struct tm *)&alarminfo->time);
+ ts.tv_sec = timegm((FAR struct tm *)&alarminfo->time);
ts.tv_nsec = 0;
/* Remember the callback information */
@@ -542,7 +542,7 @@ static int stm32_setrelative(FAR struct rtc_lowerhalf_s *lower,
{
/* Convert to seconds since the epoch */
- seconds = mktime(&time);
+ seconds = timegm(&time);
/* Add the seconds offset. Add one to the number of seconds
* because we are unsure of the phase of the timer.
@@ -600,7 +600,7 @@ static int stm32_setrelative(FAR struct rtc_lowerhalf_s *lower,
return ret;
}
- ts.tv_sec = mktime(&time);
+ ts.tv_sec = timegm(&time);
ts.tv_nsec = 0;
#elif defined(CONFIG_RTC_HIRES)
diff --git a/arch/arm/src/stm32f7/stm32_rtc_lowerhalf.c b/arch/arm/src/stm32f7/stm32_rtc_lowerhalf.c
index e1f4ce4..f78db23 100644
--- a/arch/arm/src/stm32f7/stm32_rtc_lowerhalf.c
+++ b/arch/arm/src/stm32f7/stm32_rtc_lowerhalf.c
@@ -312,7 +312,7 @@ static int stm32_settime(FAR struct rtc_lowerhalf_s *lower,
* rtc_time is cast compatible with struct tm.
*/
- ts.tv_sec = mktime((FAR struct tm *)rtctime);
+ ts.tv_sec = timegm((FAR struct tm *)rtctime);
ts.tv_nsec = 0;
/* Now set the time (to one second accuracy) */
@@ -459,7 +459,7 @@ static int stm32_setrelative(FAR struct rtc_lowerhalf_s *lower,
{
/* Convert to seconds since the epoch */
- seconds = mktime(&time);
+ seconds = timegm(&time);
/* Add the seconds offset. Add one to the number of seconds
* because we are unsure of the phase of the timer.
diff --git a/arch/arm/src/stm32h7/stm32_rtc_lowerhalf.c b/arch/arm/src/stm32h7/stm32_rtc_lowerhalf.c
index ceb1326..4166c95 100644
--- a/arch/arm/src/stm32h7/stm32_rtc_lowerhalf.c
+++ b/arch/arm/src/stm32h7/stm32_rtc_lowerhalf.c
@@ -313,7 +313,7 @@ static int stm32_settime(FAR struct rtc_lowerhalf_s *lower,
* rtc_time is cast compatible with struct tm.
*/
- ts.tv_sec = mktime((FAR struct tm *)rtctime);
+ ts.tv_sec = timegm((FAR struct tm *)rtctime);
ts.tv_nsec = 0;
/* Now set the time (to one second accuracy) */
@@ -460,7 +460,7 @@ static int stm32_setrelative(FAR struct rtc_lowerhalf_s *lower,
{
/* Convert to seconds since the epoch */
- seconds = mktime(&time);
+ seconds = timegm(&time);
/* Add the seconds offset. Add one to the number of seconds
* because we are unsure of the phase of the timer.
diff --git a/arch/arm/src/stm32l4/stm32l4_rtc_lowerhalf.c b/arch/arm/src/stm32l4/stm32l4_rtc_lowerhalf.c
index 71f3ee3..9a934c5 100644
--- a/arch/arm/src/stm32l4/stm32l4_rtc_lowerhalf.c
+++ b/arch/arm/src/stm32l4/stm32l4_rtc_lowerhalf.c
@@ -426,7 +426,7 @@ stm32l4_setrelative(FAR struct rtc_lowerhalf_s *lower,
{
/* Convert to seconds since the epoch */
- seconds = mktime(&time);
+ seconds = timegm(&time);
/* Add the seconds offset. Add one to the number of seconds
* because we are unsure of the phase of the timer.
diff --git a/arch/renesas/src/rx65n/rx65n_rtc.c b/arch/renesas/src/rx65n/rx65n_rtc.c
index 2736089..9a675b7 100644
--- a/arch/renesas/src/rx65n/rx65n_rtc.c
+++ b/arch/renesas/src/rx65n/rx65n_rtc.c
@@ -532,7 +532,7 @@ int up_rtc_gettime(FAR struct timespec *tp)
t.tm_year = rtc_bcd2dec((uint8_t) (bcd_years & 0xff)) + 100;
- tp->tv_sec = mktime(&t);
+ tp->tv_sec = timegm(&t);
tp->tv_nsec = 0;
}
diff --git a/arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c b/arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c
index 6cc9e13..bb5cfa0 100644
--- a/arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c
+++ b/arch/renesas/src/rx65n/rx65n_rtc_lowerhalf.c
@@ -303,7 +303,7 @@ static int rx65n_settime(FAR struct rtc_lowerhalf_s *lower,
* rtc_time is cast compatible with struct tm.
*/
- ts.tv_sec = mktime((FAR struct tm *)rtctime);
+ ts.tv_sec = timegm((FAR struct tm *)rtctime);
ts.tv_nsec = 0;
/* Now set the time (to one second accuracy) */
@@ -446,7 +446,7 @@ static int rx65n_setrelative(FAR struct rtc_lowerhalf_s *lower,
return ret;
}
- ts.tv_sec = mktime(&time);
+ ts.tv_sec = timegm(&time);
ts.tv_nsec = 0;
#elif defined(CONFIG_RTC_HIRES)
@@ -457,7 +457,7 @@ static int rx65n_setrelative(FAR struct rtc_lowerhalf_s *lower,
{
/* Convert to seconds since the epoch */
- seconds = mktime(&time);
+ seconds = timegm(&time);
/* Add the seconds offset. Add one to the number of seconds
* because we are unsure of the phase of the timer.
diff --git a/arch/sim/src/sim/up_rtc.c b/arch/sim/src/sim/up_rtc.c
index 628ae82..d119253 100644
--- a/arch/sim/src/sim/up_rtc.c
+++ b/arch/sim/src/sim/up_rtc.c
@@ -83,7 +83,7 @@ static int sim_rtc_rdtime(FAR struct rtc_lowerhalf_s *lower,
static int sim_rtc_settime(FAR struct rtc_lowerhalf_s *lower,
FAR const struct rtc_time *rtctime)
{
- g_sim_delta = mktime((FAR struct tm *)rtctime);
+ g_sim_delta = timegm((FAR struct tm *)rtctime);
g_sim_delta *= NSEC_PER_SEC;
g_sim_delta += rtctime->tm_nsec;
g_sim_delta -= host_gettime(true);
diff --git a/arch/z80/src/ez80/ez80_rtc_lowerhalf.c b/arch/z80/src/ez80/ez80_rtc_lowerhalf.c
index cf849ee..f7231b4 100644
--- a/arch/z80/src/ez80/ez80_rtc_lowerhalf.c
+++ b/arch/z80/src/ez80/ez80_rtc_lowerhalf.c
@@ -297,7 +297,7 @@ static int ez80_settime(FAR struct rtc_lowerhalf_s *lower,
* rtc_time is cast compatible with struct tm.
*/
- ts.tv_sec = mktime((FAR struct tm *)rtctime);
+ ts.tv_sec = timegm((FAR struct tm *)rtctime);
ts.tv_nsec = 0;
/* Now set the time (to one second accuracy) */
@@ -432,7 +432,7 @@ static int ez80_setrelative(FAR struct rtc_lowerhalf_s *lower,
{
/* Convert to seconds since the epoch */
- seconds = mktime(&time);
+ seconds = timegm(&time);
/* Add the seconds offset. Add one to the number of seconds
* because we are unsure of the phase of the timer.
diff --git a/drivers/timers/arch_rtc.c b/drivers/timers/arch_rtc.c
index 231f321..6e1b90f 100644
--- a/drivers/timers/arch_rtc.c
+++ b/drivers/timers/arch_rtc.c
@@ -89,7 +89,7 @@ time_t up_rtc_time(void)
if (g_rtc_lower->ops->rdtime(g_rtc_lower, &rtctime) == 0)
{
- time = mktime((FAR struct tm *)&rtctime);
+ time = timegm((FAR struct tm *)&rtctime);
}
}
@@ -125,7 +125,7 @@ int up_rtc_gettime(FAR struct timespec *tp)
ret = g_rtc_lower->ops->rdtime(g_rtc_lower, &rtctime);
if (ret == 0)
{
- tp->tv_sec = mktime((FAR struct tm *)&rtctime);
+ tp->tv_sec = timegm((FAR struct tm *)&rtctime);
tp->tv_nsec = rtctime.tm_nsec;
}
}
diff --git a/drivers/timers/rpmsg_rtc.c b/drivers/timers/rpmsg_rtc.c
index f0b3542..78b68d5 100644
--- a/drivers/timers/rpmsg_rtc.c
+++ b/drivers/timers/rpmsg_rtc.c
@@ -367,7 +367,7 @@ static int rpmsg_rtc_settime(FAR struct rtc_lowerhalf_s *lower,
{
struct rpmsg_rtc_set_s msg =
{
- .sec = mktime((FAR struct tm *)rtctime),
+ .sec = timegm((FAR struct tm *)rtctime),
.nsec = rtctime->tm_nsec,
};
@@ -388,7 +388,7 @@ static int rpmsg_rtc_setalarm(FAR struct rtc_lowerhalf_s *lower_,
(FAR struct rpmsg_rtc_lowerhalf_s *)lower_;
struct rpmsg_rtc_alarm_set_s msg =
{
- .sec = mktime((FAR struct tm *)&alarminfo->time),
+ .sec = timegm((FAR struct tm *)&alarminfo->time),
.nsec = alarminfo->time.tm_nsec,
.id = alarminfo->id,
};
@@ -419,7 +419,7 @@ rpmsg_rtc_setrelative(FAR struct rtc_lowerhalf_s *lower,
time_t time;
rpmsg_rtc_rdtime(lower, &alarminfo.time);
- time = mktime((FAR struct tm *)&alarminfo.time);
+ time = timegm((FAR struct tm *)&alarminfo.time);
time = time + relinfo->reltime;
gmtime_r(&time, (FAR struct tm *)&alarminfo.time);
diff --git a/fs/fat/fs_fat32util.c b/fs/fat/fs_fat32util.c
index e9f5079..7045068 100644
--- a/fs/fat/fs_fat32util.c
+++ b/fs/fat/fs_fat32util.c
@@ -465,7 +465,7 @@ time_t fat_fattime2systime(uint16_t fattime, uint16_t fatdate)
/* Then convert the broken out time into seconds since the epoch */
- return mktime(&tm);
+ return timegm(&tm);
#else
return 0;
#endif
diff --git a/include/time.h b/include/time.h
index e295457..6bca579 100644
--- a/include/time.h
+++ b/include/time.h
@@ -91,7 +91,6 @@
#define TIME_UTC 1
-
/* Redirect the timelocal */
#define timelocal mktime
diff --git a/sched/clock/clock_initialize.c b/sched/clock/clock_initialize.c
index 223e81b..7edafb7 100644
--- a/sched/clock/clock_initialize.c
+++ b/sched/clock/clock_initialize.c
@@ -92,7 +92,7 @@ int clock_basetime(FAR struct timespec *tp)
{
/* And use the broken-out time to initialize the system time */
- tp->tv_sec = mktime(&rtctime);
+ tp->tv_sec = timegm(&rtctime);
tp->tv_nsec = nsecs;
}