2.3.3-96
[glibc/history.git] / setjmp / bug269-setjmp.c
blobf50a5b1a58e57371c323184cdfe06674648e823c
1 /* Copyright (C) 2004 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */ ;
19 /* Test case for Bugzilla # 269 */
21 #include <stdio.h>
22 #include <setjmp.h>
23 #include <stdlib.h>
25 jmp_buf buf1;
26 jmp_buf buf2;
27 int *p;
28 int n_x = 6;
30 static int g_counter = 0;
32 int
33 f (void)
35 static int counter = 0;
36 static int way_point1 = 3;
37 static int way_point2 = 2;
38 int lose = 0;
40 if (setjmp (buf1) != 101)
42 int a[n_x]; /* reallocate stack space */
43 g_counter++;
44 p = &a[0];
45 if (g_counter < 5)
46 longjmp (buf1, 2);
47 else if (g_counter == 5)
48 longjmp (buf1, 101);
49 else
51 _setjmp (buf2);
52 _longjmp (buf1, 101);
56 way_point1--;
58 if (counter == 0)
60 counter++;
62 int a[n_x]; /* reallocate stack space */
63 g_counter++;
64 p = &a[0];
65 if (g_counter < 5)
66 longjmp (buf1, 2);
67 else if (g_counter == 5)
68 longjmp (buf1, 101);
69 else
71 _setjmp (buf2);
72 _longjmp (buf1, 101);
77 way_point2--;
79 if (counter == 1)
81 counter++;
82 longjmp (buf2, 2);
85 lose = !(way_point1 == 0 && way_point2 == 0
86 && g_counter == 6 && counter == 2);
88 return lose;
91 static int
92 do_test (void)
94 int lose;
96 lose = f ();
98 if (lose)
99 puts ("Test FAILED!");
100 else
101 puts ("Test succeeded!");
103 return lose ? EXIT_FAILURE : EXIT_SUCCESS;
106 #define TEST_FUNCTION do_test ()
107 #include "../test-skeleton.c"