mailing list of musl libc
 help / color / mirror / code / Atom feed
* timespec_get
@ 2014-08-01 23:11 Jens Gustedt
  0 siblings, 0 replies; only message in thread
From: Jens Gustedt @ 2014-08-01 23:11 UTC (permalink / raw)
  To: musl


[-- Attachment #1.1: Type: text/plain, Size: 916 bytes --]

Hello,
here is an implementation of the missing timespec_get function. No big
deal as long as we restrict ourselves to the minimum, that is TIME_UTC
only.

The idea is that only calling the functions with the value TIME_UTC
has defined behavior, everything else is undefined. So this
implementation here doesn't make any assumption about the value of
TIME_UTC, and just makes the implementation depending choice of doing
the right thing, anyhow. Any other TIME values that might be added
later (by standard or by implementation) change the ABI, so nobody
could expect to be compatible.

Jens


-- 
:: INRIA Nancy Grand Est ::: AlGorille ::: ICube/ICPS :::
:: ::::::::::::::: office Strasbourg : +33 368854536   ::
:: :::::::::::::::::::::: gsm France : +33 651400183   ::
:: ::::::::::::::: gsm international : +49 15737185122 ::
:: http://icube-icps.unistra.fr/index.php/Jens_Gustedt ::




[-- Attachment #1.2: timespec_get.patch --]
[-- Type: text/x-patch, Size: 908 bytes --]

diff --git a/include/time.h b/include/time.h
index dc88070..c2e4637 100644
--- a/include/time.h
+++ b/include/time.h
@@ -129,6 +129,12 @@ int stime(const time_t *);
 time_t timegm(struct tm *);
 #endif
 
+#if __STDC_VERSION__ >= 201112L
+  /* Beware that TIME_UTC per the standard must be greater than 0. */
+#define TIME_UTC 1
+int timespec_get(struct timespec *, int);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/time/timespec_get.c b/src/time/timespec_get.c
new file mode 100644
index 0000000..bf78e5a
--- /dev/null
+++ b/src/time/timespec_get.c
@@ -0,0 +1,9 @@
+#include <time.h>
+
+int __clock_gettime(clockid_t clk, struct timespec *ts);
+
+/* the base argument is simply ignored, there is no other implemented
+   value than TIME_UTC. */
+int timespec_get(struct timespec * ts, int base) {
+  return __clock_gettime(CLOCK_REALTIME, ts) < 0 ? 0 : base;
+}

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-08-01 23:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-01 23:11 timespec_get Jens Gustedt

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).