summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-04-05 15:38:20 -0400
committerRich Felker <dalias@aerifal.cx>2011-04-05 15:38:20 -0400
commitf209440bcfb5bee2386f00392f00f68c716850ce (patch)
treed65931cea9bcfec75a326655e966e9bf2ec021d2 /src
parent2c4e9e6e4b570f4dbbcc5f2402b0257a3b43380a (diff)
downloadmusl-f209440bcfb5bee2386f00392f00f68c716850ce.tar.gz
musl-f209440bcfb5bee2386f00392f00f68c716850ce.tar.bz2
musl-f209440bcfb5bee2386f00392f00f68c716850ce.tar.xz
musl-f209440bcfb5bee2386f00392f00f68c716850ce.zip
implement the adjtime and adjtimex functions (nonstandard)
Diffstat (limited to 'src')
-rw-r--r--src/linux/adjtime.c27
-rw-r--r--src/linux/adjtimex.c7
2 files changed, 34 insertions, 0 deletions
diff --git a/src/linux/adjtime.c b/src/linux/adjtime.c
new file mode 100644
index 00000000..fa8af9f0
--- /dev/null
+++ b/src/linux/adjtime.c
@@ -0,0 +1,27 @@
+#define _GNU_SOURCE
+#include <sys/time.h>
+#include <sys/timex.h>
+#include <errno.h>
+#include "syscall.h"
+
+int adjtime(const struct timeval *in, struct timeval *out)
+{
+ struct timex tx = { 0 };
+ if (in) {
+ if (in->tv_sec > 1000 || in->tv_usec > 1000000000) {
+ errno = EINVAL;
+ return -1;
+ }
+ tx.offset = in->tv_sec*1000000 + in->tv_usec;
+ tx.modes = ADJ_OFFSET_SINGLESHOT;
+ }
+ if (syscall(SYS_adjtimex, &tx) < 0) return -1;
+ if (out) {
+ out->tv_sec = tx.offset / 1000000;
+ if ((out->tv_usec = tx.offset % 1000000) < 0) {
+ out->tv_sec--;
+ out->tv_usec += 1000000;
+ }
+ }
+ return 0;
+}
diff --git a/src/linux/adjtimex.c b/src/linux/adjtimex.c
new file mode 100644
index 00000000..91de6824
--- /dev/null
+++ b/src/linux/adjtimex.c
@@ -0,0 +1,7 @@
+#include <sys/timex.h>
+#include "syscall.h"
+
+int adjtimex(struct timex *tx)
+{
+ return syscall(SYS_adjtimex, tx);
+}