summaryrefslogtreecommitdiffstats
path: root/usr/klibc/tests/setjmptest.c
blob: fd9cb1c58c3769e90b1f030d1c10971888879dfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * setjmptest.c
 */

#include <stdio.h>
#include <setjmp.h>

static jmp_buf buf;

void do_stuff(int v)
{
	printf("calling longjmp with %d... ", v + 1);
	longjmp(buf, v + 1);
}

void recurse(int ctr, int v)
{
	if (ctr--)
		recurse(ctr, v);
	else
		do_stuff(v);

	printf("ERROR!\n");	/* We should never get here... */
}

int main(void)
{
	int v;

	v = setjmp(buf);
	printf("setjmp returned %d\n", v);

	if (v < 256)
		recurse(v, v);

	return 0;
}