commit 6ecfa4adb97113e5264df6c93abc3a4ece4ebcda
parent 7fa956a2d5f377d7a7389bdb47031478b03a67cb
Author: Mykyta Holubakha <hilobakho@gmail.com>
Date: Sat, 13 Mar 2021 18:32:56 +0200
rt: add sigset and implement sigsetops
Diffstat:
2 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/rt/+linux/signal.ha b/rt/+linux/signal.ha
@@ -0,0 +1,44 @@
+// TODO: work when _NSIG != 64
+
+export fn sigemptyset(set: *sigset) int = {
+ if (set.__val[0] == 0) {
+ return 1;
+ };
+ set.__val[0] = 0;
+ return 0;
+};
+
+export fn sigaddset(set: *sigset, signum: int) (int | errno) = {
+ if (signum > NSIG) {
+ return EINVAL;
+ };
+ signum -= 1;
+ set.__val[0] |= (1 << signum): u64;
+ return 0;
+};
+
+export fn sigdelset(set: *sigset, signum: int) (int | errno) = {
+ if (signum > NSIG) {
+ return EINVAL;
+ };
+ signum -= 1;
+ set.__val[0] &= ~(1 << signum: u64);
+ return 0;
+};
+
+export fn sigismember(set: *sigset, signum: int) (int | errno) = {
+ if (signum > NSIG) {
+ return EINVAL;
+ };
+ signum -= 1;
+ if ((set.__val[0] & (1 << signum: u64)) != 0) {
+ return 1;
+ } else {
+ return 0;
+ };
+};
+
+export fn sigfillset(set: *sigset) (int | errno) = {
+ set.__val[0] = 0xffffffffffffffff: u64;
+ return 0;
+};
diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha
@@ -9,6 +9,10 @@ export type time_t = i64;
export type suseconds_t = i64;
export type nfds_t = u64;
+export type sigset = struct {
+ __val: [1]u64,
+};
+
export type timeval = struct {
tv_sec: time_t,
tv_usec: suseconds_t,