libc/time: Implement timespec_get for C11
https://en.cppreference.com/w/c/chrono/timespec_get Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: I3eb19c687cb0dc905380b10c931d66e8bb20ac55
This commit is contained in:
parent
b8b61dc070
commit
d1343df68f
1 changed files with 15 additions and 0 deletions
|
@ -96,6 +96,10 @@
|
||||||
|
|
||||||
#define TIMER_ABSTIME 1
|
#define TIMER_ABSTIME 1
|
||||||
|
|
||||||
|
/* Time base values for timespec_get. */
|
||||||
|
|
||||||
|
#define TIME_UTC 1
|
||||||
|
|
||||||
#ifndef CONFIG_LIBC_LOCALTIME
|
#ifndef CONFIG_LIBC_LOCALTIME
|
||||||
/* Local time is the same as gmtime in this implementation */
|
/* Local time is the same as gmtime in this implementation */
|
||||||
|
|
||||||
|
@ -197,6 +201,17 @@ int clock_settime(clockid_t clockid, FAR const struct timespec *tp);
|
||||||
int clock_gettime(clockid_t clockid, FAR struct timespec *tp);
|
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);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
inline int timespec_get(FAR struct timespec *t, int b)
|
||||||
|
{
|
||||||
|
return b == TIME_UTC ? (clock_gettime(CLOCK_REALTIME, t), b) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#define timespec_get(t, b) \
|
||||||
|
((b) == TIME_UTC ? (clock_gettime(CLOCK_REALTIME, (t)), (b)) : 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
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);
|
||||||
|
|
Loading…
Reference in a new issue