Home > Back-end >  Signal set functions in macOS are macros, why?
Signal set functions in macOS are macros, why?

Time:12-22

I discovered that signal sets manipulation functions are defined as macros in macOS: documentation. Then for instance, sigemptyset always results in 0 or 1, while the standard says that it can return -1 on failure.

I can fallback to the sigemptyset function by undefing it, but why is it the way it is in Mac? Is this just one of the quarks, or sigemptyset can never fail on a Mac?


Edit: I linked the "standard" to a wrong page; it should be this. I did not change the main text as the accepted answer pointed out this mistake and wanted to make it consistent.

CodePudding user response:

Providing a function as both macro and as a true function is permissible and even encouraged practice (as, e.g., a macro that expands to efficient, inline assembly). Per POSIX:

  1. Any function declared in a header may also be implemented as a macro defined in the header, so a function should not be declared explicitly if its header is included. [...]

(POSIX.1-2017 Vol. 2 §2.1.1 Use and Implementation of Functions)

With respect to the return values of sigemptyset, the standard defines no specific errors for that function, meaning it is not required to detect any errors. The sigismember function (to which you link under the name sigemptyset) has a specified error, but it is an optional "may fail" rather than a mandatory "shall fail" error detection. OS X, as you see in its documentation, detects no errors at all.

  • Related