summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/signal/setitimer.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
commit8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch)
treedf55b7e75bf43f2bf500845b105afe3ac3a5157e /libc-top-half/musl/src/signal/setitimer.c
parentInitial commit. (diff)
downloadwasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.tar.xz
wasi-libc-8c1ab65c0f548d20b7f177bdb736daaf603340e1.zip
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-top-half/musl/src/signal/setitimer.c')
-rw-r--r--libc-top-half/musl/src/signal/setitimer.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/signal/setitimer.c b/libc-top-half/musl/src/signal/setitimer.c
new file mode 100644
index 0000000..0dfbeb4
--- /dev/null
+++ b/libc-top-half/musl/src/signal/setitimer.c
@@ -0,0 +1,26 @@
+#include <sys/time.h>
+#include <errno.h>
+#include "syscall.h"
+
+#define IS32BIT(x) !((x)+0x80000000ULL>>32)
+
+int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old)
+{
+ if (sizeof(time_t) > sizeof(long)) {
+ time_t is = new->it_interval.tv_sec, vs = new->it_value.tv_sec;
+ long ius = new->it_interval.tv_usec, vus = new->it_value.tv_usec;
+ if (!IS32BIT(is) || !IS32BIT(vs))
+ return __syscall_ret(-ENOTSUP);
+ long old32[4];
+ int r = __syscall(SYS_setitimer, which,
+ ((long[]){is, ius, vs, vus}), old32);
+ if (!r && old) {
+ old->it_interval.tv_sec = old32[0];
+ old->it_interval.tv_usec = old32[1];
+ old->it_value.tv_sec = old32[2];
+ old->it_value.tv_usec = old32[3];
+ }
+ return __syscall_ret(r);
+ }
+ return syscall(SYS_setitimer, which, new, old);
+}