Reputation: 524
So, I've used signal() function several times so far, although I haven't been aware of what, actually, declaration of this function looks like. I found out that this function returns pointer to a function:
void (*signal(int sig, void (*func)(int)))(int)
And this pointer points to previous signal handler. OK, but what is this for? Does anybody use this returned pointer? Can you describe an example where this returned value is useful?
Upvotes: 3
Views: 293
Reputation: 170074
It is a general pattern for setting global values. The now old value (in this case a pointer to a handler) is returned, as a consequence of setting the new one.
This allows the change to be temporary. So one could restore the built-in handler, without forcing the implementation to expose that function to you by name.
Although in this case, the API does expose a way for you to set the default value, via the SIG_DFL
macro.
Upvotes: 3