PSB
PSB

Reputation:

How to find one's complement of sigset_t in userspace program in linux C

I want to complement signal set in my program. there are only few bit operations API provided such as sigorset() sigandset()

Is there any API to find one's complement of signal set?

Upvotes: 0

Views: 200

Answers (1)

Thomas Dickey
Thomas Dickey

Reputation: 54583

You likely are referring to sigsetops, which provides a few set-manipulation operations for signals. Only a few operations are provided, since each is intended to be used as a building block for more complicated operations.

POSIX specifies extensions for initializing signal sets to "filled" or "empty", i.e.,

Additionally, glibc adds its own extensions for logically ANDing and ORing sets. (As usual, there is a caveat about portability).

But perhaps overlooked are these POSIX extensions:

To get a one's complement of a given source operand, with these functions you would have to do something like this:

  • initialize the destination operand using sigfillset. Think of that as setting the value to all 1s.
  • iterate over the range of signal values in your source operand, using sigismember to test if a given signal is present in that signal set.
  • for each signal present in the source, use sigdelset to remove it from the destination. Think of it as setting that bit to zero.

In short, there is no predefined operation for one's complement, but you can make what you need from the existing POSIX extension functions.

Upvotes: 1

Related Questions