]>
Commit | Line | Data |
---|---|---|
185d7d97 | 1 | /* Implementation of the SIGNAL and ALARM g77 intrinsics |
36ae8a61 | 2 | Copyright (C) 2005, 2007 Free Software Foundation, Inc. |
185d7d97 FXC |
3 | Contributed by François-Xavier Coudert <coudert@clipper.ens.fr> |
4 | ||
5 | This file is part of the GNU Fortran 95 runtime library (libgfortran). | |
6 | ||
7 | Libgfortran is free software; you can redistribute it and/or | |
8 | modify it under the terms of the GNU General Public | |
9 | License as published by the Free Software Foundation; either | |
10 | version 2 of the License, or (at your option) any later version. | |
11 | ||
12 | In addition to the permissions in the GNU General Public License, the | |
13 | Free Software Foundation gives you unlimited permission to link the | |
14 | compiled version of this file into combinations with other programs, | |
15 | and to distribute those combinations without any restriction coming | |
16 | from the use of this file. (The General Public License restrictions | |
17 | do apply in other respects; for example, they cover modification of | |
18 | the file, and distribution when not linked into a combine | |
19 | executable.) | |
20 | ||
21 | Libgfortran is distributed in the hope that it will be useful, | |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
25 | ||
26 | You should have received a copy of the GNU General Public | |
27 | License along with libgfortran; see the file COPYING. If not, | |
28 | write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
29 | Boston, MA 02110-1301, USA. */ | |
30 | ||
185d7d97 FXC |
31 | #include "libgfortran.h" |
32 | ||
33 | #ifdef HAVE_UNISTD_H | |
34 | #include <unistd.h> | |
35 | #endif | |
36 | ||
37 | #ifdef HAVE_SIGNAL_H | |
38 | #include <signal.h> | |
39 | #endif | |
40 | ||
28f8c9e9 FXC |
41 | #ifdef HAVE_INTTYPES_H |
42 | #include <inttypes.h> | |
43 | #endif | |
44 | ||
185d7d97 FXC |
45 | #include <errno.h> |
46 | ||
28f8c9e9 FXC |
47 | #ifdef HAVE_INTPTR_T |
48 | # define INTPTR_T intptr_t | |
49 | #else | |
50 | # define INTPTR_T int | |
51 | #endif | |
52 | ||
185d7d97 FXC |
53 | /* SIGNAL subroutine with PROCEDURE as handler */ |
54 | extern void signal_sub (int *, void (*)(int), int *); | |
55 | iexport_proto(signal_sub); | |
56 | ||
57 | void | |
58 | signal_sub (int *number, void (*handler)(int), int *status) | |
59 | { | |
60 | #ifdef HAVE_SIGNAL | |
28f8c9e9 FXC |
61 | INTPTR_T ret; |
62 | ||
185d7d97 | 63 | if (status != NULL) |
28f8c9e9 FXC |
64 | { |
65 | ret = (INTPTR_T) signal (*number, handler); | |
66 | *status = (int) ret; | |
67 | } | |
185d7d97 FXC |
68 | else |
69 | signal (*number, handler); | |
70 | #else | |
71 | errno = ENOSYS; | |
72 | if (status != NULL) | |
73 | *status = -1; | |
74 | #endif | |
75 | } | |
76 | iexport(signal_sub); | |
77 | ||
78 | ||
79 | /* SIGNAL subroutine with INTEGER as handler */ | |
80 | extern void signal_sub_int (int *, int *, int *); | |
81 | iexport_proto(signal_sub_int); | |
82 | ||
83 | void | |
84 | signal_sub_int (int *number, int *handler, int *status) | |
85 | { | |
86 | #ifdef HAVE_SIGNAL | |
28f8c9e9 FXC |
87 | INTPTR_T ptr = *handler, ret; |
88 | ||
185d7d97 | 89 | if (status != NULL) |
28f8c9e9 FXC |
90 | { |
91 | ret = (INTPTR_T) signal (*number, (void (*)(int)) ptr); | |
92 | *status = (int) ret; | |
93 | } | |
185d7d97 | 94 | else |
28f8c9e9 | 95 | signal (*number, (void (*)(int)) ptr); |
185d7d97 FXC |
96 | #else |
97 | errno = ENOSYS; | |
98 | if (status != NULL) | |
99 | *status = -1; | |
100 | #endif | |
101 | } | |
102 | iexport(signal_sub_int); | |
103 | ||
104 | ||
105 | /* SIGNAL function with PROCEDURE as handler */ | |
106 | extern int signal_func (int *, void (*)(int)); | |
107 | iexport_proto(signal_func); | |
108 | ||
109 | int | |
110 | signal_func (int *number, void (*handler)(int)) | |
111 | { | |
112 | int status; | |
113 | signal_sub (number, handler, &status); | |
114 | return status; | |
115 | } | |
116 | iexport(signal_func); | |
117 | ||
118 | ||
119 | /* SIGNAL function with INTEGER as handler */ | |
120 | extern int signal_func_int (int *, int *); | |
121 | iexport_proto(signal_func_int); | |
122 | ||
123 | int | |
124 | signal_func_int (int *number, int *handler) | |
125 | { | |
126 | int status; | |
127 | signal_sub_int (number, handler, &status); | |
128 | return status; | |
129 | } | |
130 | iexport(signal_func_int); | |
131 | ||
132 | ||
133 | ||
134 | /* ALARM intrinsic with PROCEDURE as handler */ | |
19c222f8 FXC |
135 | extern void alarm_sub_i4 (int *, void (*)(int), GFC_INTEGER_4 *); |
136 | iexport_proto(alarm_sub_i4); | |
185d7d97 FXC |
137 | |
138 | void | |
19c222f8 | 139 | alarm_sub_i4 (int *seconds, void (*handler)(int), GFC_INTEGER_4 *status) |
185d7d97 FXC |
140 | { |
141 | #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL) | |
142 | if (status != NULL) | |
143 | { | |
144 | if (signal (SIGALRM, handler) == SIG_ERR) | |
145 | *status = -1; | |
146 | else | |
147 | *status = alarm (*seconds); | |
148 | } | |
149 | else | |
150 | { | |
151 | signal (SIGALRM, handler); | |
152 | alarm (*seconds); | |
153 | } | |
154 | #else | |
155 | errno = ENOSYS; | |
156 | if (status != NULL) | |
157 | *status = -1; | |
158 | #endif | |
159 | } | |
19c222f8 FXC |
160 | iexport(alarm_sub_i4); |
161 | ||
162 | ||
163 | extern void alarm_sub_i8 (int *, void (*)(int), GFC_INTEGER_8 *); | |
164 | iexport_proto(alarm_sub_i8); | |
165 | ||
166 | void | |
167 | alarm_sub_i8 (int *seconds, void (*handler)(int), GFC_INTEGER_8 *status) | |
168 | { | |
169 | #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL) | |
170 | if (status != NULL) | |
171 | { | |
172 | if (signal (SIGALRM, handler) == SIG_ERR) | |
173 | *status = -1; | |
174 | else | |
175 | *status = alarm (*seconds); | |
176 | } | |
177 | else | |
178 | { | |
179 | signal (SIGALRM, handler); | |
180 | alarm (*seconds); | |
181 | } | |
182 | #else | |
183 | errno = ENOSYS; | |
184 | if (status != NULL) | |
185 | *status = -1; | |
186 | #endif | |
187 | } | |
188 | iexport(alarm_sub_i8); | |
185d7d97 FXC |
189 | |
190 | ||
191 | /* ALARM intrinsic with INTEGER as handler */ | |
19c222f8 FXC |
192 | extern void alarm_sub_int_i4 (int *, int *, GFC_INTEGER_4 *); |
193 | iexport_proto(alarm_sub_int_i4); | |
194 | ||
195 | void | |
196 | alarm_sub_int_i4 (int *seconds, int *handler, GFC_INTEGER_4 *status) | |
197 | { | |
198 | #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL) | |
199 | if (status != NULL) | |
200 | { | |
1cc0507d | 201 | if (signal (SIGALRM, (void (*)(int)) (INTPTR_T) *handler) == SIG_ERR) |
19c222f8 FXC |
202 | *status = -1; |
203 | else | |
204 | *status = alarm (*seconds); | |
205 | } | |
206 | else | |
207 | { | |
1cc0507d | 208 | signal (SIGALRM, (void (*)(int)) (INTPTR_T) *handler); |
19c222f8 FXC |
209 | alarm (*seconds); |
210 | } | |
211 | #else | |
212 | errno = ENOSYS; | |
213 | if (status != NULL) | |
214 | *status = -1; | |
215 | #endif | |
216 | } | |
217 | iexport(alarm_sub_int_i4); | |
218 | ||
219 | ||
220 | extern void alarm_sub_int_i8 (int *, int *, GFC_INTEGER_8 *); | |
221 | iexport_proto(alarm_sub_int_i8); | |
185d7d97 FXC |
222 | |
223 | void | |
19c222f8 | 224 | alarm_sub_int_i8 (int *seconds, int *handler, GFC_INTEGER_8 *status) |
185d7d97 FXC |
225 | { |
226 | #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL) | |
227 | if (status != NULL) | |
228 | { | |
1cc0507d | 229 | if (signal (SIGALRM, (void (*)(int)) (INTPTR_T) *handler) == SIG_ERR) |
185d7d97 FXC |
230 | *status = -1; |
231 | else | |
232 | *status = alarm (*seconds); | |
233 | } | |
234 | else | |
235 | { | |
1cc0507d | 236 | signal (SIGALRM, (void (*)(int)) (INTPTR_T) *handler); |
185d7d97 FXC |
237 | alarm (*seconds); |
238 | } | |
239 | #else | |
240 | errno = ENOSYS; | |
241 | if (status != NULL) | |
242 | *status = -1; | |
243 | #endif | |
244 | } | |
19c222f8 | 245 | iexport(alarm_sub_int_i8); |
185d7d97 | 246 |