Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libgfortran / intrinsics / signal.c
blob9e403585027c1fc6812310f4a48d6868ce7c2c49
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
18 executable.)
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. */
30 #include "config.h"
31 #include "libgfortran.h"
33 #ifdef HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif
37 #ifdef HAVE_SIGNAL_H
38 #include <signal.h>
39 #endif
41 #include <errno.h>
43 /* SIGNAL subroutine with PROCEDURE as handler */
44 extern void signal_sub (int *, void (*)(int), int *);
45 iexport_proto(signal_sub);
47 void
48 signal_sub (int *number, void (*handler)(int), int *status)
50 #ifdef HAVE_SIGNAL
51 if (status != NULL)
52 *status = (int) signal (*number, handler);
53 else
54 signal (*number, handler);
55 #else
56 errno = ENOSYS;
57 if (status != NULL)
58 *status = -1;
59 #endif
61 iexport(signal_sub);
64 /* SIGNAL subroutine with INTEGER as handler */
65 extern void signal_sub_int (int *, int *, int *);
66 iexport_proto(signal_sub_int);
68 void
69 signal_sub_int (int *number, int *handler, int *status)
71 #ifdef HAVE_SIGNAL
72 if (status != NULL)
73 *status = (int) signal (*number, (void (*)(int)) *handler);
74 else
75 signal (*number, (void (*)(int)) *handler);
76 #else
77 errno = ENOSYS;
78 if (status != NULL)
79 *status = -1;
80 #endif
82 iexport(signal_sub_int);
85 /* SIGNAL function with PROCEDURE as handler */
86 extern int signal_func (int *, void (*)(int));
87 iexport_proto(signal_func);
89 int
90 signal_func (int *number, void (*handler)(int))
92 int status;
93 signal_sub (number, handler, &status);
94 return status;
96 iexport(signal_func);
99 /* SIGNAL function with INTEGER as handler */
100 extern int signal_func_int (int *, int *);
101 iexport_proto(signal_func_int);
104 signal_func_int (int *number, int *handler)
106 int status;
107 signal_sub_int (number, handler, &status);
108 return status;
110 iexport(signal_func_int);
114 /* ALARM intrinsic with PROCEDURE as handler */
115 extern void alarm_sub (int *, void (*)(int), int *);
116 iexport_proto(alarm_sub);
118 void
119 alarm_sub (int *seconds, void (*handler)(int), int *status)
121 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
122 if (status != NULL)
124 if (signal (SIGALRM, handler) == SIG_ERR)
125 *status = -1;
126 else
127 *status = alarm (*seconds);
129 else
131 signal (SIGALRM, handler);
132 alarm (*seconds);
134 #else
135 errno = ENOSYS;
136 if (status != NULL)
137 *status = -1;
138 #endif
140 iexport(alarm_sub);
143 /* ALARM intrinsic with INTEGER as handler */
144 extern void alarm_sub_int (int *, int *, int *);
145 iexport_proto(alarm_sub_int);
147 void
148 alarm_sub_int (int *seconds, int *handler, int *status)
150 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
151 if (status != NULL)
153 if (signal (SIGALRM, (void (*)(int)) handler) == SIG_ERR)
154 *status = -1;
155 else
156 *status = alarm (*seconds);
158 else
160 signal (SIGALRM, (void (*)(int)) handler);
161 alarm (*seconds);
163 #else
164 errno = ENOSYS;
165 if (status != NULL)
166 *status = -1;
167 #endif
169 iexport(alarm_sub_int);