aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/options/internal/generic/sigset.cpp
blob: 134277d5682815725d85f5cc9c5e576b211134af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/sigset_t.h>
#include <bits/ensure.h>

int sigemptyset(sigset_t *sigset) {
	*sigset = 0;
	return 0;
}

int sigfillset(sigset_t *sigset) {
	*sigset = ~sigset_t(0);
	return 0;
}

// TODO: Return EINVAL instead of __ensure()ing.

int sigaddset(sigset_t *sigset, int sig) {
	int signo = sig - 1;
	// TODO: do not hard code CHAR_BITS
	__ensure((unsigned int)signo < sizeof(sigset_t) * 8);
	*sigset |= sigset_t(1) << signo;
	return 0;
}

int sigdelset(sigset_t *sigset, int sig) {
	int signo = sig - 1;
	// TODO: do not hard code CHAR_BITS
	__ensure((unsigned int)signo < sizeof(sigset_t) * 8);
	*sigset &= ~(sigset_t(1) << signo);
	return 0;
}

int sigismember(const sigset_t *set, int sig) {
	int signo = sig - 1;
	// TODO: do not hard code CHAR_BITS
	__ensure((unsigned int)signo < sizeof(sigset_t) * 8);
	return (*set) & (sigset_t(1) << signo);
}