#define _GNU_SOURCE #include #include #include static sigjmp_buf buf; static void handler(int sig) { siglongjmp(buf, 1); } int essayer(void (*f)(), int sig) { int r = 0; struct sigaction sa, old; sa.sa_handler = handler; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(sig, &sa, &old); if(sigsetjmp(buf, 1) == 0) f(); else r = 1; sigaction(sig, &old, NULL); return r; } void toto() { *(int *)0L = 12; // SEGV } int main(int argc, char *argv[]) { printf("essai de toto : %s\n", essayer(toto, SIGSEGV) == 0 ? "ok" : "echec"); return 0; }