This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit d1343df68fd39df1b80f8be312becf43de162fba
Author: Xiang Xiao <[email protected]>
AuthorDate: Mon Jun 1 14:17:51 2020 +0800

    libc/time: Implement timespec_get for C11
    
    https://en.cppreference.com/w/c/chrono/timespec_get
    
    Signed-off-by: Xiang Xiao <[email protected]>
    Change-Id: I3eb19c687cb0dc905380b10c931d66e8bb20ac55
---
 include/time.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/time.h b/include/time.h
index ee949db..eb0f163 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);

Reply via email to