OSDN Git Service

* config/i386/i386.md (*strmovsi_1): Simplify asm alternatives.
[pf3gnuchains/gcc-fork.git] / libgfortran / intrinsics / signal.c
1 /* Implementation of the SIGNAL and ALARM g77 intrinsics
2    Copyright (C) 2005, 2007 Free Software Foundation, Inc.
3    Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
4
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
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 2 of the License, or (at your option) any later version.
11
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file.  (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
19 executable.)
20
21 Libgfortran is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public
27 License along with libgfortran; see the file COPYING.  If not,
28 write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 Boston, MA 02110-1301, USA.  */
30
31 #include "libgfortran.h"
32
33 #ifdef HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif
36
37 #ifdef HAVE_SIGNAL_H
38 #include <signal.h>
39 #endif
40
41 #ifdef HAVE_INTTYPES_H
42 #include <inttypes.h>
43 #endif
44
45 #include <errno.h>
46
47 /* SIGNAL subroutine with PROCEDURE as handler  */
48 extern void signal_sub (int *, void (*)(int), int *);
49 iexport_proto(signal_sub);
50
51 void
52 signal_sub (int *number, void (*handler)(int), int *status)
53 {
54 #ifdef HAVE_SIGNAL
55   intptr_t ret;
56
57   if (status != NULL)
58     {
59       ret = (intptr_t) signal (*number, handler);
60       *status = (int) ret;
61     }
62   else
63     signal (*number, handler);
64 #else
65   errno = ENOSYS;
66   if (status != NULL)
67     *status = -1;
68 #endif
69 }
70 iexport(signal_sub);
71
72
73 /* SIGNAL subroutine with INTEGER as handler  */
74 extern void signal_sub_int (int *, int *, int *);
75 iexport_proto(signal_sub_int);
76
77 void
78 signal_sub_int (int *number, int *handler, int *status)
79 {
80 #ifdef HAVE_SIGNAL
81   intptr_t ptr = *handler, ret;
82
83   if (status != NULL)
84     {
85       ret = (intptr_t) signal (*number, (void (*)(int)) ptr);
86       *status = (int) ret;
87     }
88   else
89     signal (*number, (void (*)(int)) ptr);
90 #else
91   errno = ENOSYS;
92   if (status != NULL)
93     *status = -1;
94 #endif
95 }
96 iexport(signal_sub_int);
97
98
99 /* SIGNAL function with PROCEDURE as handler  */
100 extern int signal_func (int *, void (*)(int));
101 iexport_proto(signal_func);
102
103 int
104 signal_func (int *number, void (*handler)(int))
105 {
106   int status;
107   signal_sub (number, handler, &status);
108   return status;
109 }
110 iexport(signal_func);
111
112
113 /* SIGNAL function with INTEGER as handler  */
114 extern int signal_func_int (int *, int *);
115 iexport_proto(signal_func_int);
116
117 int
118 signal_func_int (int *number, int *handler)
119 {
120   int status;
121   signal_sub_int (number, handler, &status);
122   return status;
123 }
124 iexport(signal_func_int);
125
126
127
128 /* ALARM intrinsic with PROCEDURE as handler  */
129 extern void alarm_sub_i4 (int *, void (*)(int), GFC_INTEGER_4 *);
130 iexport_proto(alarm_sub_i4);
131
132 void
133 alarm_sub_i4 (int * seconds __attribute__ ((unused)),
134               void (*handler)(int) __attribute__ ((unused)),
135               GFC_INTEGER_4 *status)
136 {
137 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
138   if (status != NULL)
139     {
140       if (signal (SIGALRM, handler) == SIG_ERR)
141         *status = -1;
142       else
143         *status = alarm (*seconds);
144     }
145   else
146     {
147       signal (SIGALRM, handler);
148       alarm (*seconds);
149     }
150 #else
151   errno = ENOSYS;
152   if (status != NULL)
153     *status = -1;
154 #endif
155 }
156 iexport(alarm_sub_i4);
157
158
159 extern void alarm_sub_i8 (int *, void (*)(int), GFC_INTEGER_8 *);
160 iexport_proto(alarm_sub_i8);
161
162 void
163 alarm_sub_i8 (int *seconds __attribute__ ((unused)),
164               void (*handler)(int) __attribute__ ((unused)),
165               GFC_INTEGER_8 *status)
166 {
167 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
168   if (status != NULL)
169     {
170       if (signal (SIGALRM, handler) == SIG_ERR)
171         *status = -1;
172       else
173         *status = alarm (*seconds);
174     }
175   else
176     {
177       signal (SIGALRM, handler);
178       alarm (*seconds);
179     }
180 #else
181   errno = ENOSYS;
182   if (status != NULL)
183     *status = -1;
184 #endif
185 }
186 iexport(alarm_sub_i8);
187
188
189 /* ALARM intrinsic with INTEGER as handler  */
190 extern void alarm_sub_int_i4 (int *, int *, GFC_INTEGER_4 *);
191 iexport_proto(alarm_sub_int_i4);
192
193 void
194 alarm_sub_int_i4 (int *seconds __attribute__ ((unused)),
195                   int *handler __attribute__ ((unused)),
196                   GFC_INTEGER_4 *status)
197 {
198 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
199   if (status != NULL)
200     {
201       if (signal (SIGALRM, (void (*)(int)) (intptr_t) *handler) == SIG_ERR)
202         *status = -1;
203       else
204         *status = alarm (*seconds);
205     }
206   else
207     {
208       signal (SIGALRM, (void (*)(int)) (intptr_t) *handler);
209       alarm (*seconds);
210     }
211 #else
212   errno = ENOSYS;
213   if (status != NULL)
214     *status = -1;
215 #endif
216 }
217 iexport(alarm_sub_int_i4);
218
219
220 extern void alarm_sub_int_i8 (int *, int *, GFC_INTEGER_8 *);
221 iexport_proto(alarm_sub_int_i8);
222
223 void
224 alarm_sub_int_i8 (int *seconds __attribute__ ((unused)),
225                   int *handler __attribute__ ((unused)),
226                   GFC_INTEGER_8 *status)
227 {
228 #if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
229   if (status != NULL)
230     {
231       if (signal (SIGALRM, (void (*)(int)) (intptr_t) *handler) == SIG_ERR)
232         *status = -1;
233       else
234         *status = alarm (*seconds);
235     }
236   else
237     {
238       signal (SIGALRM, (void (*)(int)) (intptr_t) *handler);
239       alarm (*seconds);
240     }
241 #else
242   errno = ENOSYS;
243   if (status != NULL)
244     *status = -1;
245 #endif
246 }
247 iexport(alarm_sub_int_i8);
248