1 /* Implementation of the SIGNAL and ALARM g77 intrinsics
2 Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
4 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6 Libgfortran is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file into combinations with other programs,
14 and to distribute those combinations without any restriction coming
15 from the use of this file. (The General Public License restrictions
16 do apply in other respects; for example, they cover modification of
17 the file, and distribution when not linked into a combine
20 Libgfortran is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public
26 License along with libgfortran; see the file COPYING. If not,
27 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
28 Boston, MA 02110-1301, USA. */
31 #include "libgfortran.h"
41 #ifdef HAVE_INTTYPES_H
48 # define INTPTR_T intptr_t
53 /* SIGNAL subroutine with PROCEDURE as handler */
54 extern void signal_sub (int *, void (*)(int), int *);
55 iexport_proto(signal_sub
);
58 signal_sub (int *number
, void (*handler
)(int), int *status
)
65 ret
= (INTPTR_T
) signal (*number
, handler
);
69 signal (*number
, handler
);
79 /* SIGNAL subroutine with INTEGER as handler */
80 extern void signal_sub_int (int *, int *, int *);
81 iexport_proto(signal_sub_int
);
84 signal_sub_int (int *number
, int *handler
, int *status
)
87 INTPTR_T ptr
= *handler
, ret
;
91 ret
= (INTPTR_T
) signal (*number
, (void (*)(int)) ptr
);
95 signal (*number
, (void (*)(int)) ptr
);
102 iexport(signal_sub_int
);
105 /* SIGNAL function with PROCEDURE as handler */
106 extern int signal_func (int *, void (*)(int));
107 iexport_proto(signal_func
);
110 signal_func (int *number
, void (*handler
)(int))
113 signal_sub (number
, handler
, &status
);
116 iexport(signal_func
);
119 /* SIGNAL function with INTEGER as handler */
120 extern int signal_func_int (int *, int *);
121 iexport_proto(signal_func_int
);
124 signal_func_int (int *number
, int *handler
)
127 signal_sub_int (number
, handler
, &status
);
130 iexport(signal_func_int
);
134 /* ALARM intrinsic with PROCEDURE as handler */
135 extern void alarm_sub (int *, void (*)(int), int *);
136 iexport_proto(alarm_sub
);
139 alarm_sub (int *seconds
, void (*handler
)(int), int *status
)
141 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
144 if (signal (SIGALRM
, handler
) == SIG_ERR
)
147 *status
= alarm (*seconds
);
151 signal (SIGALRM
, handler
);
163 /* ALARM intrinsic with INTEGER as handler */
164 extern void alarm_sub_int (int *, int *, int *);
165 iexport_proto(alarm_sub_int
);
168 alarm_sub_int (int *seconds
, int *handler
, int *status
)
170 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
173 if (signal (SIGALRM
, (void (*)(int)) *handler
) == SIG_ERR
)
176 *status
= alarm (*seconds
);
180 signal (SIGALRM
, (void (*)(int)) *handler
);
189 iexport(alarm_sub_int
);