aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/sys/linux/sigset.c
blob: b6f2d79e590b78a0e08e6e766c2d0eba5bde6bf1 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* sigset.c - signal set manipulation functions */

/* Copyright 2002, Red Hat Inc. */

/* Note: these are currently grouped together in one file so that
         it will override the default version in the libc/unix 
         directory which has grouped all functions in one file. */

/* sigaddset function */

#include <signal.h>
#include <bits/sigset.h>
#include <errno.h>
#include <string.h>
#include <machine/weakalias.h>

int
sigaddset (sigset_t *set, const int signo)
{
  int index, mask;
  __sigset_t *st = (__sigset_t *)set;

  if (signo > NSIG)
    {
      errno = EINVAL;
      return -1;
    }

  index = (signo - 1) / (8 * sizeof(long));
  mask = 1 << ((signo - 1) % (8 * sizeof(long)));

  st->__val[index] |= mask;
  return 0;
}

/* sigdelset function */

int
sigdelset (sigset_t *set, const int signo)
{
  int index, mask;
  __sigset_t *st = (__sigset_t *)set;

  if (signo > NSIG)
    {
      errno = EINVAL;
      return -1;
    }

  index = (signo - 1) / (8 * sizeof(long));
  mask = 1 << ((signo - 1) % (8 * sizeof(long)));

  st->__val[index] &= ~mask;
  return 0;
}

/* sigemptyset function */

int
sigemptyset (sigset_t *set)
{
  int size = NSIG / 8;
  __sigset_t *st = (__sigset_t *)set;
  memset (st->__val, 0, size);
  return 0;
}

/* sigfillset function */

int
sigfillset (sigset_t *set)
{
  int size = NSIG / 8;
  __sigset_t *st = (__sigset_t *)set;
  memset (st->__val, 0xff, size);
  return 0;
}

/* sigismember function */

int
sigismember (const sigset_t *set, int signo)
{
  int index, mask;
  __sigset_t *st = (__sigset_t *)set;

  if (signo > NSIG)
    {
      errno = EINVAL;
      return -1;
    }

  index = (signo - 1) / (8 * sizeof(long));
  mask = 1 << ((signo - 1) % (8 * sizeof(long)));

  return (st->__val[index] & mask) != 0;
}