musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/linux/adjtime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/linux/adjtime.c')
-rw-r--r--src/linux/adjtime.c 27
1 files changed, 27 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;
+}
generated by cgit v1.2.1 (git 2.18.0) at 2025年10月08日 03:06:52 +0000

AltStyle によって変換されたページ (->オリジナル) /