commit 1b46fe71a4f63865f163f5006ea9325990f9cce5
parent a6e4f31c161be443ea37ddc059eca540a7dead80
Author: Curtis Arthaud <uku82@gmx.fr>
Date: Mon, 27 May 2024 13:45:07 +0200
time: add set()
Signed-off-by: Curtis Arthaud <uku82@gmx.fr>
Diffstat:
4 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/time/+freebsd/functions.ha b/time/+freebsd/functions.ha
@@ -92,3 +92,13 @@ export fn now(clock: clock) instant = {
abort("Unexpected error from clock_gettime");
};
};
+
+// Sets system clock to given time.
+export fn set(clock: clock, t: instant) void = {
+ let tp = instant_to_timespec(t);
+ match (rt::clock_settime(clock, &tp)) {
+ case void => yield;
+ case let err: rt::errno =>
+ abort("Unexpected error from clock_settime");
+ };
+};
diff --git a/time/+linux/functions.ha b/time/+linux/functions.ha
@@ -128,3 +128,13 @@ export fn now(clock: clock) instant = {
abort("Unexpected error from clock_gettime");
};
};
+
+// Sets system clock to given time.
+export fn set(clock: clock, t: instant) void = {
+ let tp = instant_to_timespec(t);
+ match (rt::clock_settime(clock, &tp)) {
+ case void => yield;
+ case let err: rt::errno =>
+ abort("Unexpected error from clock_settime");
+ };
+};
diff --git a/time/+netbsd/functions.ha b/time/+netbsd/functions.ha
@@ -93,3 +93,13 @@ export fn now(clock: clock) instant = {
abort("Unexpected error from clock_gettime");
};
};
+
+// Sets system clock to given time.
+export fn set(clock: clock, t: instant) void = {
+ let tp = instant_to_timespec(t);
+ match (rt::clock_settime(clock, &tp)) {
+ case void => yield;
+ case let err: rt::errno =>
+ abort("Unexpected error from clock_settime");
+ };
+};
diff --git a/time/+openbsd/functions.ha b/time/+openbsd/functions.ha
@@ -94,3 +94,13 @@ export fn now(clock: clock) instant = {
abort("Unexpected error from clock_gettime");
};
};
+
+// Sets system clock to given time.
+export fn set(clock: clock, t: instant) void = {
+ let tp = instant_to_timespec(t);
+ match (rt::clock_settime(clock, &tp)) {
+ case void => yield;
+ case let err: rt::errno =>
+ abort("Unexpected error from clock_settime");
+ };
+};