lang-specs.h: Ensure -mrtp switch is passed when using either rtp-smp or ravenscar...
[official-gcc.git] / libgfortran / intrinsics / signal.c
blob66e54f33af00ab1ff7f2e90a124bc0db84fed920
1 /* Implementation of the SIGNAL and ALARM g77 intrinsics
2 Copyright (C) 2005, 2007, 2009 Free Software Foundation, Inc.
3 Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
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 3 of the License, or (at your option) any later version.
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #include "libgfortran.h"
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
32 #ifdef HAVE_SIGNAL_H
33 #include <signal.h>
34 #endif
36 #ifdef HAVE_INTTYPES_H
37 #include <inttypes.h>
38 #endif
40 #include <errno.h>
42 /* SIGNAL subroutine with PROCEDURE as handler */
43 extern void signal_sub (int *, void (*)(int), int *);
44 iexport_proto(signal_sub);
46 void
47 signal_sub (int *number, void (*handler)(int), int *status)
49 #ifdef HAVE_SIGNAL
50 intptr_t ret;
52 if (status != NULL)
54 ret = (intptr_t) signal (*number, handler);
55 *status = (int) ret;
57 else
58 signal (*number, handler);
59 #else
60 errno = ENOSYS;
61 if (status != NULL)
62 *status = -1;
63 #endif
65 iexport(signal_sub);
68 /* SIGNAL subroutine with INTEGER as handler */
69 extern void signal_sub_int (int *, int *, int *);
70 iexport_proto(signal_sub_int);
72 void
73 signal_sub_int (int *number, int *handler, int *status)
75 #ifdef HAVE_SIGNAL
76 intptr_t ptr = *handler, ret;
78 if (status != NULL)
80 ret = (intptr_t) signal (*number, (void (*)(int)) ptr);
81 *status = (int) ret;
83 else
84 signal (*number, (void (*)(int)) ptr);
85 #else
86 errno = ENOSYS;
87 if (status != NULL)
88 *status = -1;
89 #endif
91 iexport(signal_sub_int);
94 /* SIGNAL function with PROCEDURE as handler */
95 extern int signal_func (int *, void (*)(int));
96 iexport_proto(signal_func);
98 int
99 signal_func (int *number, void (*handler)(int))
101 int status;
102 signal_sub (number, handler, &status);
103 return status;
105 iexport(signal_func);
108 /* SIGNAL function with INTEGER as handler */
109 extern int signal_func_int (int *, int *);
110 iexport_proto(signal_func_int);
113 signal_func_int (int *number, int *handler)
115 int status;
116 signal_sub_int (number, handler, &status);
117 return status;
119 iexport(signal_func_int);
123 /* ALARM intrinsic with PROCEDURE as handler */
124 extern void alarm_sub_i4 (int *, void (*)(int), GFC_INTEGER_4 *);
125 iexport_proto(alarm_sub_i4);
127 void
128 alarm_sub_i4 (int * seconds __attribute__ ((unused)),
129 void (*handler)(int) __attribute__ ((unused)),
130 GFC_INTEGER_4 *status)
132 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
133 if (status != NULL)
135 if (signal (SIGALRM, handler) == SIG_ERR)
136 *status = -1;
137 else
138 *status = alarm (*seconds);
140 else
142 signal (SIGALRM, handler);
143 alarm (*seconds);
145 #else
146 errno = ENOSYS;
147 if (status != NULL)
148 *status = -1;
149 #endif
151 iexport(alarm_sub_i4);
154 extern void alarm_sub_i8 (int *, void (*)(int), GFC_INTEGER_8 *);
155 iexport_proto(alarm_sub_i8);
157 void
158 alarm_sub_i8 (int *seconds __attribute__ ((unused)),
159 void (*handler)(int) __attribute__ ((unused)),
160 GFC_INTEGER_8 *status)
162 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
163 if (status != NULL)
165 if (signal (SIGALRM, handler) == SIG_ERR)
166 *status = -1;
167 else
168 *status = alarm (*seconds);
170 else
172 signal (SIGALRM, handler);
173 alarm (*seconds);
175 #else
176 errno = ENOSYS;
177 if (status != NULL)
178 *status = -1;
179 #endif
181 iexport(alarm_sub_i8);
184 /* ALARM intrinsic with INTEGER as handler */
185 extern void alarm_sub_int_i4 (int *, int *, GFC_INTEGER_4 *);
186 iexport_proto(alarm_sub_int_i4);
188 void
189 alarm_sub_int_i4 (int *seconds __attribute__ ((unused)),
190 int *handler __attribute__ ((unused)),
191 GFC_INTEGER_4 *status)
193 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
194 if (status != NULL)
196 if (signal (SIGALRM, (void (*)(int)) (intptr_t) *handler) == SIG_ERR)
197 *status = -1;
198 else
199 *status = alarm (*seconds);
201 else
203 signal (SIGALRM, (void (*)(int)) (intptr_t) *handler);
204 alarm (*seconds);
206 #else
207 errno = ENOSYS;
208 if (status != NULL)
209 *status = -1;
210 #endif
212 iexport(alarm_sub_int_i4);
215 extern void alarm_sub_int_i8 (int *, int *, GFC_INTEGER_8 *);
216 iexport_proto(alarm_sub_int_i8);
218 void
219 alarm_sub_int_i8 (int *seconds __attribute__ ((unused)),
220 int *handler __attribute__ ((unused)),
221 GFC_INTEGER_8 *status)
223 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
224 if (status != NULL)
226 if (signal (SIGALRM, (void (*)(int)) (intptr_t) *handler) == SIG_ERR)
227 *status = -1;
228 else
229 *status = alarm (*seconds);
231 else
233 signal (SIGALRM, (void (*)(int)) (intptr_t) *handler);
234 alarm (*seconds);
236 #else
237 errno = ENOSYS;
238 if (status != NULL)
239 *status = -1;
240 #endif
242 iexport(alarm_sub_int_i8);