libc/time: Implement timegm function

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Id988ae077cf54597b2522546c4309b66416b8b0e
This commit is contained in:
Xiang Xiao
2021-06-22 00:28:56 +08:00
committed by Alan Carvalho de Assis
parent 55312052a7
commit b1cd825cac
6 changed files with 19 additions and 10 deletions
+5 -2
View File
@@ -91,9 +91,10 @@
#define TIME_UTC 1 #define TIME_UTC 1
/* Redirect the timegm */
#define timegm mktime /* Redirect the timelocal */
#define timelocal mktime
/******************************************************************************** /********************************************************************************
* Public Types * 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 clock_getres(clockid_t clockid, FAR struct timespec *res);
int timespec_get(FAR struct timespec *t, int b); int timespec_get(FAR struct timespec *t, int b);
time_t timegm(FAR struct tm *tp);
time_t mktime(FAR struct tm *tp); time_t mktime(FAR struct tm *tp);
FAR struct tm *gmtime(FAR const time_t *timep); FAR struct tm *gmtime(FAR const time_t *timep);
FAR struct tm *gmtime_r(FAR const time_t *timep, FAR struct tm *result); FAR struct tm *gmtime_r(FAR const time_t *timep, FAR struct tm *result);
+1 -1
View File
@@ -29,7 +29,7 @@ CSRCS += lib_gethrtime.c
ifdef CONFIG_LIBC_LOCALTIME ifdef CONFIG_LIBC_LOCALTIME
CSRCS += lib_localtime.c CSRCS += lib_localtime.c
else else
CSRCS += lib_mktime.c lib_gmtime.c lib_gmtimer.c CSRCS += lib_timegm.c lib_gmtime.c lib_gmtimer.c
endif endif
# Add the time directory to the build # Add the time directory to the build
-2
View File
@@ -48,9 +48,7 @@ FAR struct tm *gmtime(FAR const time_t *timep)
return gmtime_r(timep, &tm); return gmtime_r(timep, &tm);
} }
#ifndef CONFIG_LIBC_LOCALTIME
FAR struct tm *localtime(FAR const time_t *timep) FAR struct tm *localtime(FAR const time_t *timep)
{ {
return gmtime(timep); return gmtime(timep);
} }
#endif
-2
View File
@@ -344,9 +344,7 @@ FAR struct tm *gmtime_r(FAR const time_t *timep, FAR struct tm *result)
return result; return result;
} }
#ifndef CONFIG_LIBC_LOCALTIME
FAR struct tm *localtime_r(FAR const time_t *timep, FAR struct tm *result) FAR struct tm *localtime_r(FAR const time_t *timep, FAR struct tm *result)
{ {
return gmtime_r(timep, result); return gmtime_r(timep, result);
} }
#endif
+5
View File
@@ -2604,3 +2604,8 @@ time_t mktime(struct tm * const tmp)
tzset(); tzset();
return time1(tmp, localsub, 0L); return time1(tmp, localsub, 0L);
} }
time_t timegm(FAR struct tm *tmp)
{
return time1(tmp, gmtsub, 0L);
}
@@ -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 * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * contributor license agreements. See the NOTICE file distributed with
@@ -62,14 +62,14 @@
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: mktime * Name: timegm
* *
* Description: * Description:
* Time conversion (based on the POSIX API) * 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 ret;
time_t jdn; time_t jdn;
@@ -90,3 +90,8 @@ time_t mktime(FAR struct tm *tp)
return ret; return ret;
} }
time_t mktime(FAR struct tm *tp)
{
return timegm(tp);
}