summaryrefslogtreecommitdiff
path: root/src/signal/sigsetjmp.c
blob: a6667a27964f39a321cc1ba78b2923e3d24d47b5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <setjmp.h>
#include <signal.h>
#include <stdlib.h>

/* !!! This function will not work unless the compiler performs
 * tail call optimization. Machine-specific asm versions should
 * be created instead even though the workaround (tail call)
 * is entirely non-machine-specific... */

int sigsetjmp(sigjmp_buf buf, int save)
{
	long *flag = buf + sizeof(jmp_buf)/sizeof(long);
	sigset_t *mask = (void *)(flag + 1);
	if ((*flag = save))
		sigprocmask (SIG_SETMASK, NULL, mask);
	return setjmp((void *)buf);
}