]>
Commit | Line | Data |
---|---|---|
568035b7 | 1 | /* Copyright (C) 1991-2013 Free Software Foundation, Inc. |
c84142e8 | 2 | This file is part of the GNU C Library. |
28f540f4 | 3 | |
c84142e8 | 4 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
28f540f4 | 8 | |
c84142e8 UD |
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 | |
41bdb6e2 | 12 | Lesser General Public License for more details. |
28f540f4 | 13 | |
41bdb6e2 | 14 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
15 | License along with the GNU C Library; if not, see |
16 | <http://www.gnu.org/licenses/>. */ | |
28f540f4 | 17 | |
28f540f4 RM |
18 | #include <stdio.h> |
19 | #include <setjmp.h> | |
20 | #include <stdlib.h> | |
21 | ||
22 | static jmp_buf env; | |
23 | static int last_value = -1, lose = 0; | |
24 | ||
de149cdb | 25 | static void |
c84142e8 | 26 | jump (int val) |
28f540f4 | 27 | { |
c84142e8 | 28 | longjmp (env, val); |
28f540f4 RM |
29 | } |
30 | ||
31 | int | |
c84142e8 | 32 | main (void) |
28f540f4 RM |
33 | { |
34 | int value; | |
35 | ||
c84142e8 | 36 | value = setjmp (env); |
28f540f4 RM |
37 | if (value != last_value + 1) |
38 | { | |
39 | fputs("Shouldn't have ", stdout); | |
40 | lose = 1; | |
41 | } | |
42 | last_value = value; | |
43 | switch (value) | |
44 | { | |
45 | case 0: | |
46 | puts("Saved environment."); | |
c84142e8 | 47 | jump (0); |
28f540f4 | 48 | default: |
c84142e8 | 49 | printf ("Jumped to %d.\n", value); |
28f540f4 | 50 | if (value < 10) |
c84142e8 | 51 | jump (value + 1); |
28f540f4 RM |
52 | } |
53 | ||
e61abf83 UD |
54 | if (!lose && value == 10) |
55 | { | |
c57abfa7 UD |
56 | /* Do a second test, this time without `setjmp' being a macro. |
57 | This is not required by ISO C but we have this for compatibility. */ | |
e61abf83 | 58 | #undef setjmp |
c57abfa7 UD |
59 | extern int setjmp (jmp_buf); |
60 | ||
61 | last_value = -1; | |
62 | lose = 0; | |
63 | ||
e61abf83 UD |
64 | value = setjmp (env); |
65 | if (value != last_value + 1) | |
66 | { | |
67 | fputs("Shouldn't have ", stdout); | |
68 | lose = 1; | |
69 | } | |
70 | last_value = value; | |
71 | switch (value) | |
72 | { | |
73 | case 0: | |
74 | puts("Saved environment."); | |
75 | jump (0); | |
76 | default: | |
77 | printf ("Jumped to %d.\n", value); | |
78 | if (value < 10) | |
79 | jump (value + 1); | |
80 | } | |
81 | } | |
82 | ||
c57abfa7 UD |
83 | if (!lose && value == 10) |
84 | { | |
cb343854 UD |
85 | /* And again for the `_setjmp' function. */ |
86 | #ifndef _setjmp | |
87 | extern int _setjmp (jmp_buf); | |
88 | #endif | |
c57abfa7 UD |
89 | last_value = -1; |
90 | lose = 0; | |
91 | ||
cb343854 | 92 | value = _setjmp (env); |
c57abfa7 UD |
93 | if (value != last_value + 1) |
94 | { | |
95 | fputs("Shouldn't have ", stdout); | |
96 | lose = 1; | |
97 | } | |
98 | last_value = value; | |
99 | switch (value) | |
100 | { | |
101 | case 0: | |
102 | puts("Saved environment."); | |
103 | jump (0); | |
104 | default: | |
105 | printf ("Jumped to %d.\n", value); | |
106 | if (value < 10) | |
107 | jump (value + 1); | |
108 | } | |
109 | } | |
110 | ||
28f540f4 | 111 | if (lose || value != 10) |
c84142e8 | 112 | puts ("Test FAILED!"); |
28f540f4 | 113 | else |
c84142e8 | 114 | puts ("Test succeeded!"); |
bf4de8f3 AJ |
115 | |
116 | return lose ? EXIT_FAILURE : EXIT_SUCCESS; | |
28f540f4 | 117 | } |