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"
36 #ifdef HAVE_INTTYPES_H
42 /* SIGNAL subroutine with PROCEDURE as handler */
43 extern void signal_sub (int *, void (*)(int), int *);
44 iexport_proto(signal_sub
);
47 signal_sub (int *number
, void (*handler
)(int), int *status
)
54 ret
= (intptr_t) signal (*number
, handler
);
58 signal (*number
, handler
);
68 /* SIGNAL subroutine with INTEGER as handler */
69 extern void signal_sub_int (int *, int *, int *);
70 iexport_proto(signal_sub_int
);
73 signal_sub_int (int *number
, int *handler
, int *status
)
76 intptr_t ptr
= *handler
, ret
;
80 ret
= (intptr_t) signal (*number
, (void (*)(int)) ptr
);
84 signal (*number
, (void (*)(int)) ptr
);
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
);
99 signal_func (int *number
, void (*handler
)(int))
102 signal_sub (number
, handler
, &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
)
116 signal_sub_int (number
, handler
, &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
);
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)
135 if (signal (SIGALRM
, handler
) == SIG_ERR
)
138 *status
= alarm (*seconds
);
142 signal (SIGALRM
, handler
);
151 iexport(alarm_sub_i4
);
154 extern void alarm_sub_i8 (int *, void (*)(int), GFC_INTEGER_8
*);
155 iexport_proto(alarm_sub_i8
);
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)
165 if (signal (SIGALRM
, handler
) == SIG_ERR
)
168 *status
= alarm (*seconds
);
172 signal (SIGALRM
, handler
);
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
);
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)
196 if (signal (SIGALRM
, (void (*)(int)) (intptr_t) *handler
) == SIG_ERR
)
199 *status
= alarm (*seconds
);
203 signal (SIGALRM
, (void (*)(int)) (intptr_t) *handler
);
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
);
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)
226 if (signal (SIGALRM
, (void (*)(int)) (intptr_t) *handler
) == SIG_ERR
)
229 *status
= alarm (*seconds
);
233 signal (SIGALRM
, (void (*)(int)) (intptr_t) *handler
);
242 iexport(alarm_sub_int_i8
);