From b1cd825cac7ad6139968c3b32c53f4628d73b9a2 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Tue, 22 Jun 2021 00:28:56 +0800 Subject: [PATCH] libc/time: Implement timegm function Signed-off-by: Xiang Xiao Change-Id: Id988ae077cf54597b2522546c4309b66416b8b0e --- include/time.h | 7 +++++-- libs/libc/time/Make.defs | 2 +- libs/libc/time/lib_gmtime.c | 2 -- libs/libc/time/lib_gmtimer.c | 2 -- libs/libc/time/lib_localtime.c | 5 +++++ libs/libc/time/{lib_mktime.c => lib_timegm.c} | 11 ++++++++--- 6 files changed, 19 insertions(+), 10 deletions(-) rename libs/libc/time/{lib_mktime.c => lib_timegm.c} (97%) diff --git a/include/time.h b/include/time.h index f0ed66ddb7..e2954577ab 100644 --- a/include/time.h +++ b/include/time.h @@ -91,9 +91,10 @@ #define TIME_UTC 1 -/* Redirect the timegm */ -#define timegm mktime +/* Redirect the timelocal */ + +#define timelocal mktime /******************************************************************************** * Public Types @@ -192,7 +193,9 @@ int clock_gettime(clockid_t clockid, FAR struct timespec *tp); int clock_getres(clockid_t clockid, FAR struct timespec *res); int timespec_get(FAR struct timespec *t, int b); +time_t timegm(FAR struct tm *tp); 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); diff --git a/libs/libc/time/Make.defs b/libs/libc/time/Make.defs index e74072d5c4..65553c6c1c 100644 --- a/libs/libc/time/Make.defs +++ b/libs/libc/time/Make.defs @@ -29,7 +29,7 @@ CSRCS += lib_gethrtime.c ifdef CONFIG_LIBC_LOCALTIME CSRCS += lib_localtime.c else -CSRCS += lib_mktime.c lib_gmtime.c lib_gmtimer.c +CSRCS += lib_timegm.c lib_gmtime.c lib_gmtimer.c endif # Add the time directory to the build diff --git a/libs/libc/time/lib_gmtime.c b/libs/libc/time/lib_gmtime.c index 780e3f89b0..a474fd86de 100644 --- a/libs/libc/time/lib_gmtime.c +++ b/libs/libc/time/lib_gmtime.c @@ -48,9 +48,7 @@ FAR struct tm *gmtime(FAR const time_t *timep) 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 380d40a439..99a1db0a4b 100644 --- a/libs/libc/time/lib_gmtimer.c +++ b/libs/libc/time/lib_gmtimer.c @@ -344,9 +344,7 @@ FAR struct tm *gmtime_r(FAR const time_t *timep, 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 diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c index 99d65d9803..62769e5696 100644 --- a/libs/libc/time/lib_localtime.c +++ b/libs/libc/time/lib_localtime.c @@ -2604,3 +2604,8 @@ time_t mktime(struct tm * const tmp) tzset(); return time1(tmp, localsub, 0L); } + +time_t timegm(FAR struct tm *tmp) +{ + return time1(tmp, gmtsub, 0L); +} diff --git a/libs/libc/time/lib_mktime.c b/libs/libc/time/lib_timegm.c similarity index 97% rename from libs/libc/time/lib_mktime.c rename to libs/libc/time/lib_timegm.c index 7d2c02870e..86471d95ad 100644 --- a/libs/libc/time/lib_mktime.c +++ b/libs/libc/time/lib_timegm.c @@ -1,5 +1,5 @@ /**************************************************************************** - * libs/libc/time/lib_mktime.c + * libs/libc/time/lib_timegm.c * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -62,14 +62,14 @@ ****************************************************************************/ /**************************************************************************** - * Name: mktime + * Name: timegm * * Description: * Time conversion (based on the POSIX API) * ****************************************************************************/ -time_t mktime(FAR struct tm *tp) +time_t timegm(FAR struct tm *tp) { time_t ret; time_t jdn; @@ -90,3 +90,8 @@ time_t mktime(FAR struct tm *tp) return ret; } + +time_t mktime(FAR struct tm *tp) +{ + return timegm(tp); +}