]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
support: Add xclock_now helper function.
authorMike Crowe <mac@mcrowe.com>
Wed, 19 Jun 2019 21:05:12 +0000 (18:05 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 21 Jun 2019 12:59:50 +0000 (09:59 -0300)
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.

ChangeLog
support/xtime.h

index 05291d782500899cf6e625d0f5dc1c17492b0a77..de58169b6129e79c2214a8aef10399aae72f5efd 100644 (file)
--- 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>
 
index 68af1a59d7835e94411157c0625433760320eb13..6e19ce177f58b51ff4b14264d4d5d271229a3b2d 100644 (file)
@@ -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 */