about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMike Crowe <mac@mcrowe.com>2019-06-19 18:05:12 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-06-21 09:59:50 -0300
commitdb13e32cb8d5f74fe61880459c7ddf8f47da436b (patch)
tree3fa0b0b97ac6547a7b8390f88f0834bbbc1c88ca
parent21cc130b78a4db9113fb6695e2b951e697662440 (diff)
downloadglibc-db13e32cb8d5f74fe61880459c7ddf8f47da436b.tar.gz
glibc-db13e32cb8d5f74fe61880459c7ddf8f47da436b.tar.xz
glibc-db13e32cb8d5f74fe61880459c7ddf8f47da436b.zip
support: Add xclock_now helper function.
It's easier to read and write tests with:

 const struct timespec ts = xclock_now(CLOCK_REALTIME);

than

 struct timespec ts;
 xclock_gettime(CLOCK_REALTIME, &ts);

	* support/xtime.h: Add xclock_now() helper function.
-rw-r--r--ChangeLog4
-rw-r--r--support/xtime.h10
2 files changed, 14 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 05291d7825..de58169b61 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2019-06-20  Mike Crowe  <mac@mcrowe.com>
+
+	* support/xtime.h: Add xclock_now() helper function.
+
 2019-06-20  Dmitry V. Levin  <ldv@altlinux.org>
 	    Florian Weimer  <fweimer@redhat.com>
 
diff --git a/support/xtime.h b/support/xtime.h
index 68af1a59d7..6e19ce177f 100644
--- a/support/xtime.h
+++ b/support/xtime.h
@@ -28,6 +28,16 @@ __BEGIN_DECLS
 
 void xclock_gettime (clockid_t clock, struct timespec *ts);
 
+/* This helper can often simplify tests by avoiding an explicit
+   variable declaration or allowing that declaration to be const. */
+
+static inline struct timespec xclock_now (clockid_t clock)
+{
+  struct timespec ts;
+  xclock_gettime (clock, &ts);
+  return ts;
+}
+
 __END_DECLS
 
 #endif /* SUPPORT_TIME_H */