diff --git a/include/time.h b/include/time.h index ee949db70a9..eb0f1632e44 100644 --- a/include/time.h +++ b/include/time.h @@ -96,6 +96,10 @@ #define TIMER_ABSTIME 1 +/* Time base values for timespec_get. */ + +#define TIME_UTC 1 + #ifndef CONFIG_LIBC_LOCALTIME /* 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_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); FAR struct tm *gmtime(FAR const time_t *timep); FAR struct tm *gmtime_r(FAR const time_t *timep, FAR struct tm *result);