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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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