diff options
author | deraadt <> | 1995-10-18 08:49:34 +0000 |
---|---|---|
committer | deraadt <> | 1995-10-18 08:49:34 +0000 |
commit | a4f79641824cbf9f60ca9d1168d1fcc46717a82a (patch) | |
tree | 3a9a60a6831189695ecfa7eb6904bce69aec0bcb /src/regress/lib/libc/setjmp/jmptest.c | |
parent | 0527d29da443886d92e9a418180c5b25a5f8d270 (diff) | |
download | openbsd-a4f79641824cbf9f60ca9d1168d1fcc46717a82a.tar.gz openbsd-a4f79641824cbf9f60ca9d1168d1fcc46717a82a.tar.bz2 openbsd-a4f79641824cbf9f60ca9d1168d1fcc46717a82a.zip |
initial import of NetBSD tree
Diffstat (limited to 'src/regress/lib/libc/setjmp/jmptest.c')
-rw-r--r-- | src/regress/lib/libc/setjmp/jmptest.c | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/src/regress/lib/libc/setjmp/jmptest.c b/src/regress/lib/libc/setjmp/jmptest.c new file mode 100644 index 0000000000..f2cecc9178 --- /dev/null +++ b/src/regress/lib/libc/setjmp/jmptest.c | |||
@@ -0,0 +1,134 @@ | |||
1 | /* $NetBSD: jmptest.c,v 1.2 1995/01/01 20:55:35 jtc Exp $ */ | ||
2 | |||
3 | /* | ||
4 | * Copyright (c) 1994 Christopher G. Demetriou | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. All advertising materials mentioning features or use of this software | ||
16 | * must display the following acknowledgement: | ||
17 | * This product includes software developed by Christopher G. Demetriou | ||
18 | * for the NetBSD Project. | ||
19 | * 4. The name of the author may not be used to endorse or promote products | ||
20 | * derived from this software without specific prior written permission | ||
21 | * | ||
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
23 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
25 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
27 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
28 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
29 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
30 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
31 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
32 | */ | ||
33 | |||
34 | #include <sys/types.h> | ||
35 | #include <setjmp.h> | ||
36 | #include <signal.h> | ||
37 | #include <stdio.h> | ||
38 | #include <stdlib.h> | ||
39 | #include <unistd.h> | ||
40 | |||
41 | #if (TEST_SETJMP + TEST_U_SETJMP + TEST_SIGSETJMP) != 1 | ||
42 | #error one of TEST_SETJMP, TEST_U_SETJMP, or TEST_SIGSETJMP must be defined | ||
43 | #endif | ||
44 | |||
45 | #ifdef TEST_SETJMP | ||
46 | #define BUF jmp_buf | ||
47 | #define SET(b, m) setjmp(b) | ||
48 | #define JMP(b, v) longjmp(b, v) | ||
49 | #endif | ||
50 | |||
51 | #ifdef TEST_U_SETJMP | ||
52 | #define BUF jmp_buf | ||
53 | #define SET(b, m) _setjmp(b) | ||
54 | #define JMP(b, v) _longjmp(b, v) | ||
55 | #endif | ||
56 | |||
57 | #ifdef TEST_SIGSETJMP | ||
58 | #define BUF sigjmp_buf | ||
59 | #define SET(b, m) sigsetjmp(b, m) | ||
60 | #define JMP(b, v) siglongjmp(b, v) | ||
61 | #endif | ||
62 | |||
63 | int expectsignal; | ||
64 | |||
65 | void | ||
66 | aborthandler(signo) | ||
67 | int signo; | ||
68 | { | ||
69 | |||
70 | if (expectsignal) | ||
71 | exit(0); | ||
72 | else | ||
73 | errx(1, "kill(SIGABRT) succeeded"); | ||
74 | } | ||
75 | |||
76 | int | ||
77 | main(argc, argv) | ||
78 | int argc; | ||
79 | char *argv[]; | ||
80 | { | ||
81 | struct sigaction sa; | ||
82 | BUF jb; | ||
83 | sigset_t ss; | ||
84 | int i, x; | ||
85 | |||
86 | i = getpid(); | ||
87 | |||
88 | #ifdef TEST_SETJMP | ||
89 | expectsignal = 0; | ||
90 | #endif | ||
91 | #ifdef TEST_U_SETJMP | ||
92 | expectsignal = 1; | ||
93 | #endif | ||
94 | #ifdef TEST_SIGSETJMP | ||
95 | if (argc != 2 || | ||
96 | (strcmp(argv[1], "save") && strcmp(argv[1], "nosave"))) { | ||
97 | fprintf(stderr, "usage: %s [save|nosave]\n", argv[0]); | ||
98 | exit(1); | ||
99 | } | ||
100 | expectsignal = (strcmp(argv[1], "save") != 0); | ||
101 | #endif | ||
102 | |||
103 | sa.sa_handler = aborthandler; | ||
104 | sa.sa_mask = 0; | ||
105 | sa.sa_flags = 0; | ||
106 | if (sigaction(SIGABRT, &sa, NULL) == -1) | ||
107 | err(1, "sigaction failed"); | ||
108 | |||
109 | if (sigemptyset(&ss) == -1) | ||
110 | err(1, "sigemptyset failed"); | ||
111 | if (sigaddset(&ss, SIGABRT) == -1) | ||
112 | err(1, "sigaddset failed"); | ||
113 | if (sigprocmask(SIG_BLOCK, &ss, NULL) == -1) | ||
114 | err(1, "sigprocmask (1) failed"); | ||
115 | |||
116 | x = SET(jb, !expectsignal); | ||
117 | if (x != 0) { | ||
118 | if (x != i) | ||
119 | errx(1, "setjmp returned wrong value"); | ||
120 | |||
121 | kill(i, SIGABRT); | ||
122 | if (expectsignal) | ||
123 | errx(1, "kill(SIGABRT) failed"); | ||
124 | else | ||
125 | exit(0); | ||
126 | } | ||
127 | |||
128 | if (sigprocmask(SIG_UNBLOCK, &ss, NULL) == -1) | ||
129 | err(1, "sigprocmask (2) failed"); | ||
130 | |||
131 | JMP(jb, i); | ||
132 | |||
133 | errx(1, "jmp failed"); | ||
134 | } | ||