]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/intrinsics/signal.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / intrinsics / signal.c
CommitLineData
185d7d97 1/* Implementation of the SIGNAL and ALARM g77 intrinsics
a945c346 2 Copyright (C) 2005-2024 Free Software Foundation, Inc.
185d7d97
FXC
3 Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
4
74544378 5This file is part of the GNU Fortran runtime library (libgfortran).
185d7d97
FXC
6
7Libgfortran is free software; you can redistribute it and/or
8modify it under the terms of the GNU General Public
9License as published by the Free Software Foundation; either
748086b7 10version 3 of the License, or (at your option) any later version.
185d7d97
FXC
11
12Libgfortran is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
748086b7
JJ
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
185d7d97 25
185d7d97
FXC
26#include "libgfortran.h"
27
28#ifdef HAVE_UNISTD_H
29#include <unistd.h>
30#endif
31
185d7d97 32#include <signal.h>
185d7d97 33
28f8c9e9
FXC
34#ifdef HAVE_INTTYPES_H
35#include <inttypes.h>
36#endif
37
185d7d97
FXC
38#include <errno.h>
39
40/* SIGNAL subroutine with PROCEDURE as handler */
41extern void signal_sub (int *, void (*)(int), int *);
42iexport_proto(signal_sub);
43
44void
45signal_sub (int *number, void (*handler)(int), int *status)
46{
c7d0f4d5 47 intptr_t ret;
28f8c9e9 48
185d7d97 49 if (status != NULL)
28f8c9e9 50 {
c7d0f4d5 51 ret = (intptr_t) signal (*number, handler);
28f8c9e9
FXC
52 *status = (int) ret;
53 }
185d7d97
FXC
54 else
55 signal (*number, handler);
185d7d97
FXC
56}
57iexport(signal_sub);
58
59
60/* SIGNAL subroutine with INTEGER as handler */
61extern void signal_sub_int (int *, int *, int *);
62iexport_proto(signal_sub_int);
63
64void
65signal_sub_int (int *number, int *handler, int *status)
66{
c7d0f4d5 67 intptr_t ptr = *handler, ret;
28f8c9e9 68
185d7d97 69 if (status != NULL)
28f8c9e9 70 {
c7d0f4d5 71 ret = (intptr_t) signal (*number, (void (*)(int)) ptr);
28f8c9e9
FXC
72 *status = (int) ret;
73 }
185d7d97 74 else
28f8c9e9 75 signal (*number, (void (*)(int)) ptr);
185d7d97
FXC
76}
77iexport(signal_sub_int);
78
79
80/* SIGNAL function with PROCEDURE as handler */
81extern int signal_func (int *, void (*)(int));
82iexport_proto(signal_func);
83
84int
85signal_func (int *number, void (*handler)(int))
86{
87 int status;
88 signal_sub (number, handler, &status);
89 return status;
90}
91iexport(signal_func);
92
93
94/* SIGNAL function with INTEGER as handler */
95extern int signal_func_int (int *, int *);
96iexport_proto(signal_func_int);
97
98int
99signal_func_int (int *number, int *handler)
100{
101 int status;
102 signal_sub_int (number, handler, &status);
103 return status;
104}
105iexport(signal_func_int);
106
107
108
109/* ALARM intrinsic with PROCEDURE as handler */
19c222f8
FXC
110extern void alarm_sub_i4 (int *, void (*)(int), GFC_INTEGER_4 *);
111iexport_proto(alarm_sub_i4);
185d7d97
FXC
112
113void
6525c3f0
BE
114alarm_sub_i4 (int * seconds __attribute__ ((unused)),
115 void (*handler)(int) __attribute__ ((unused)),
116 GFC_INTEGER_4 *status)
185d7d97 117{
74544378 118#if defined (SIGALRM) && defined (HAVE_ALARM)
185d7d97
FXC
119 if (status != NULL)
120 {
121 if (signal (SIGALRM, handler) == SIG_ERR)
122 *status = -1;
123 else
124 *status = alarm (*seconds);
125 }
126 else
127 {
128 signal (SIGALRM, handler);
129 alarm (*seconds);
130 }
131#else
132 errno = ENOSYS;
133 if (status != NULL)
134 *status = -1;
135#endif
136}
19c222f8
FXC
137iexport(alarm_sub_i4);
138
139
140extern void alarm_sub_i8 (int *, void (*)(int), GFC_INTEGER_8 *);
141iexport_proto(alarm_sub_i8);
142
143void
6525c3f0
BE
144alarm_sub_i8 (int *seconds __attribute__ ((unused)),
145 void (*handler)(int) __attribute__ ((unused)),
146 GFC_INTEGER_8 *status)
19c222f8 147{
74544378 148#if defined (SIGALRM) && defined (HAVE_ALARM)
19c222f8
FXC
149 if (status != NULL)
150 {
151 if (signal (SIGALRM, handler) == SIG_ERR)
152 *status = -1;
153 else
154 *status = alarm (*seconds);
155 }
156 else
157 {
158 signal (SIGALRM, handler);
159 alarm (*seconds);
160 }
161#else
162 errno = ENOSYS;
163 if (status != NULL)
164 *status = -1;
165#endif
166}
167iexport(alarm_sub_i8);
185d7d97
FXC
168
169
170/* ALARM intrinsic with INTEGER as handler */
19c222f8
FXC
171extern void alarm_sub_int_i4 (int *, int *, GFC_INTEGER_4 *);
172iexport_proto(alarm_sub_int_i4);
173
174void
6525c3f0
BE
175alarm_sub_int_i4 (int *seconds __attribute__ ((unused)),
176 int *handler __attribute__ ((unused)),
177 GFC_INTEGER_4 *status)
19c222f8 178{
74544378 179#if defined (SIGALRM) && defined (HAVE_ALARM)
19c222f8
FXC
180 if (status != NULL)
181 {
c7d0f4d5 182 if (signal (SIGALRM, (void (*)(int)) (intptr_t) *handler) == SIG_ERR)
19c222f8
FXC
183 *status = -1;
184 else
185 *status = alarm (*seconds);
186 }
187 else
188 {
c7d0f4d5 189 signal (SIGALRM, (void (*)(int)) (intptr_t) *handler);
19c222f8
FXC
190 alarm (*seconds);
191 }
192#else
193 errno = ENOSYS;
194 if (status != NULL)
195 *status = -1;
196#endif
197}
198iexport(alarm_sub_int_i4);
199
200
201extern void alarm_sub_int_i8 (int *, int *, GFC_INTEGER_8 *);
202iexport_proto(alarm_sub_int_i8);
185d7d97
FXC
203
204void
6525c3f0
BE
205alarm_sub_int_i8 (int *seconds __attribute__ ((unused)),
206 int *handler __attribute__ ((unused)),
207 GFC_INTEGER_8 *status)
185d7d97 208{
74544378 209#if defined (SIGALRM) && defined (HAVE_ALARM)
185d7d97
FXC
210 if (status != NULL)
211 {
c7d0f4d5 212 if (signal (SIGALRM, (void (*)(int)) (intptr_t) *handler) == SIG_ERR)
185d7d97
FXC
213 *status = -1;
214 else
215 *status = alarm (*seconds);
216 }
217 else
218 {
c7d0f4d5 219 signal (SIGALRM, (void (*)(int)) (intptr_t) *handler);
185d7d97
FXC
220 alarm (*seconds);
221 }
222#else
223 errno = ENOSYS;
224 if (status != NULL)
225 *status = -1;
226#endif
227}
19c222f8 228iexport(alarm_sub_int_i8);
185d7d97 229