OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libgfortran/] [intrinsics/] [signal.c] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* Implementation of the SIGNAL and ALARM g77 intrinsics
2
   Contributed by François-Xavier Coudert <coudert@clipper.ens.fr>
3
 
4
This file is part of the GNU Fortran 95 runtime library (libgfortran).
5
 
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.
10
 
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.)
19
 
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.
24
 
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.  */
29
 
30
#include "config.h"
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
#include <errno.h>
42
 
43
/* SIGNAL subroutine with PROCEDURE as handler  */
44
extern void signal_sub (int *, void (*)(int), int *);
45
iexport_proto(signal_sub);
46
 
47
void
48
signal_sub (int *number, void (*handler)(int), int *status)
49
{
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
60
}
61
iexport(signal_sub);
62
 
63
 
64
/* SIGNAL subroutine with INTEGER as handler  */
65
extern void signal_sub_int (int *, int *, int *);
66
iexport_proto(signal_sub_int);
67
 
68
void
69
signal_sub_int (int *number, int *handler, int *status)
70
{
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
81
}
82
iexport(signal_sub_int);
83
 
84
 
85
/* SIGNAL function with PROCEDURE as handler  */
86
extern int signal_func (int *, void (*)(int));
87
iexport_proto(signal_func);
88
 
89
int
90
signal_func (int *number, void (*handler)(int))
91
{
92
  int status;
93
  signal_sub (number, handler, &status);
94
  return status;
95
}
96
iexport(signal_func);
97
 
98
 
99
/* SIGNAL function with INTEGER as handler  */
100
extern int signal_func_int (int *, int *);
101
iexport_proto(signal_func_int);
102
 
103
int
104
signal_func_int (int *number, int *handler)
105
{
106
  int status;
107
  signal_sub_int (number, handler, &status);
108
  return status;
109
}
110
iexport(signal_func_int);
111
 
112
 
113
 
114
/* ALARM intrinsic with PROCEDURE as handler  */
115
extern void alarm_sub (int *, void (*)(int), int *);
116
iexport_proto(alarm_sub);
117
 
118
void
119
alarm_sub (int *seconds, void (*handler)(int), int *status)
120
{
121
#if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
122
  if (status != NULL)
123
    {
124
      if (signal (SIGALRM, handler) == SIG_ERR)
125
        *status = -1;
126
      else
127
        *status = alarm (*seconds);
128
    }
129
  else
130
    {
131
      signal (SIGALRM, handler);
132
      alarm (*seconds);
133
    }
134
#else
135
  errno = ENOSYS;
136
  if (status != NULL)
137
    *status = -1;
138
#endif
139
}
140
iexport(alarm_sub);
141
 
142
 
143
/* ALARM intrinsic with INTEGER as handler  */
144
extern void alarm_sub_int (int *, int *, int *);
145
iexport_proto(alarm_sub_int);
146
 
147
void
148
alarm_sub_int (int *seconds, int *handler, int *status)
149
{
150
#if defined (SIGALRM) && defined (HAVE_ALARM) && defined (HAVE_SIGNAL)
151
  if (status != NULL)
152
    {
153
      if (signal (SIGALRM, (void (*)(int)) handler) == SIG_ERR)
154
        *status = -1;
155
      else
156
        *status = alarm (*seconds);
157
    }
158
  else
159
    {
160
      signal (SIGALRM, (void (*)(int)) handler);
161
      alarm (*seconds);
162
    }
163
#else
164
  errno = ENOSYS;
165
  if (status != NULL)
166
    *status = -1;
167
#endif
168
}
169
iexport(alarm_sub_int);
170
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.