168855535SJérôme Duval/*
29b28f887SAxel Dörfler * Copyright 2005-2006, Axel D��rfler, axeld@pinc-software.de.
368855535SJérôme Duval * Distributed under the terms of the MIT License.
468855535SJérôme Duval */
568855535SJérôme Duval
668855535SJérôme Duval
768855535SJérôme Duval#include <setjmp.h>
89b28f887SAxel Dörfler#include <stdio.h>
99b28f887SAxel Dörfler
1068855535SJérôme Duval
119b28f887SAxel Dörflerstatic void
1268855535SJérôme Duvaljump_to_top_level(jmp_buf *state, int value)
1368855535SJérôme Duval{
1468855535SJérôme Duval	siglongjmp(*state, value);
1568855535SJérôme Duval}
1668855535SJérôme Duval
1768855535SJérôme Duval
1868855535SJérôme Duvalint
1968855535SJérôme Duvalmain(int argc, char **argv)
2068855535SJérôme Duval{
2168855535SJérôme Duval	jmp_buf state;
2268855535SJérôme Duval	int value;
2368855535SJérôme Duval
249b28f887SAxel Dörfler	if ((value = sigsetjmp(state, 1)) != 0) {
2568855535SJérôme Duval		printf("failed with: %d!\n", value);
2668855535SJérôme Duval	} else {
2768855535SJérôme Duval		printf("here I am: %d\n", value);
2868855535SJérôme Duval		jump_to_top_level(&state, 42);
2968855535SJérôme Duval		printf("you won't see me!\n");
3068855535SJérôme Duval	}
3168855535SJérôme Duval
3268855535SJérôme Duval	puts("done.");
3368855535SJérôme Duval	return 0;
3468855535SJérôme Duval}