summaryrefslogtreecommitdiff
path: root/test/setjmp/setjmp_test.c
blob: f371048a58d618ab7e095c2299151d8500403f8f (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

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


jmp_buf jb;
int tries=0;

int main(int argc,char *argv[])
{
	int ret;

	printf("calling setjmp, should return with 0\n");

	ret = setjmp(jb);
	
	printf("setjmp returned %d\n",ret);

	if(!ret){
		if(tries++>4){
			printf("Hmmm... in loop, must be broken.\n");
			return 0;
		}
		printf("now calling longjmp, setjmp should return with 1\n");

		longjmp(jb,1);

		printf("returned from longjmp, must be broken\n");
		return 0;
	}

	return 0;
}