]>
Commit | Line | Data |
---|---|---|
7401123f GM |
1 | /* GSelective.c provides access to select for Modula-2. |
2 | ||
3d864fce | 3 | Copyright (C) 2016-2022 Free Software Foundation, Inc. |
7401123f GM |
4 | Contributed by Gaius Mulley <gaius@glam.ac.uk>. |
5 | ||
6 | This file is part of GNU Modula-2. | |
7 | ||
8 | GNU Modula-2 is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 3, or (at your option) | |
11 | any later version. | |
12 | ||
13 | GNU Modula-2 is distributed in the hope that it will be useful, but | |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU Modula-2; see the file COPYING3. If not see | |
20 | <http://www.gnu.org/licenses/>. */ | |
21 | ||
22 | /* implementation module in C. */ | |
23 | ||
24 | #include "config.h" | |
25 | #include "system.h" | |
26 | #include "ansidecl.h" | |
27 | ||
28 | #include "gm2-libs-host.h" | |
29 | ||
30 | /* PROCEDURE Select (nooffds: CARDINAL; readfds, writefds, exceptfds: | |
31 | SetOfFd; timeout: Timeval) : INTEGER ; */ | |
32 | ||
33 | #if defined(HAVE_SELECT) | |
34 | int | |
35 | Selective_Select (int nooffds, fd_set *readfds, fd_set *writefds, | |
36 | fd_set *exceptfds, struct timeval *timeout) | |
37 | { | |
38 | return select (nooffds, readfds, writefds, exceptfds, timeout); | |
39 | } | |
40 | #else | |
41 | int | |
42 | Selective_Select (int nooffds, void *readfds, void *writefds, void *exceptfds, | |
43 | void *timeout) | |
44 | { | |
45 | return 0; | |
46 | } | |
47 | #endif | |
48 | ||
49 | /* PROCEDURE InitTime (sec, usec) : Timeval ; */ | |
50 | ||
51 | #if defined(HAVE_SELECT) | |
52 | struct timeval * | |
53 | Selective_InitTime (unsigned int sec, unsigned int usec) | |
54 | { | |
55 | struct timeval *t = (struct timeval *)malloc (sizeof (struct timeval)); | |
56 | ||
57 | t->tv_sec = (long int)sec; | |
58 | t->tv_usec = (long int)usec; | |
59 | return t; | |
60 | } | |
61 | ||
62 | void | |
63 | Selective_GetTime (struct timeval *t, unsigned int *sec, unsigned int *usec) | |
64 | { | |
65 | *sec = (unsigned int)t->tv_sec; | |
66 | *usec = (unsigned int)t->tv_usec; | |
67 | } | |
68 | ||
69 | void | |
70 | Selective_SetTime (struct timeval *t, unsigned int sec, unsigned int usec) | |
71 | { | |
72 | t->tv_sec = sec; | |
73 | t->tv_usec = usec; | |
74 | } | |
75 | ||
76 | /* PROCEDURE KillTime (t: Timeval) : Timeval ; */ | |
77 | ||
78 | struct timeval * | |
79 | Selective_KillTime (struct timeval *t) | |
80 | { | |
81 | free (t); | |
82 | return NULL; | |
83 | } | |
84 | ||
85 | /* PROCEDURE InitSet () : SetOfFd ; */ | |
86 | ||
87 | fd_set * | |
88 | Selective_InitSet (void) | |
89 | { | |
90 | fd_set *s = (fd_set *)malloc (sizeof (fd_set)); | |
91 | ||
92 | return s; | |
93 | } | |
94 | ||
95 | /* PROCEDURE KillSet (s: SetOfFd) : SetOfFd ; */ | |
96 | ||
97 | fd_set * | |
98 | Selective_KillSet (fd_set *s) | |
99 | { | |
100 | free (s); | |
101 | return NULL; | |
102 | } | |
103 | ||
104 | /* PROCEDURE FdZero (s: SetOfFd) ; */ | |
105 | ||
106 | void | |
107 | Selective_FdZero (fd_set *s) | |
108 | { | |
109 | FD_ZERO (s); | |
110 | } | |
111 | ||
112 | /* PROCEDURE Fd_Set (fd: INTEGER; SetOfFd) ; */ | |
113 | ||
114 | void | |
115 | Selective_FdSet (int fd, fd_set *s) | |
116 | { | |
117 | FD_SET (fd, s); | |
118 | } | |
119 | ||
120 | /* PROCEDURE FdClr (fd: INTEGER; SetOfFd) ; */ | |
121 | ||
122 | void | |
123 | Selective_FdClr (int fd, fd_set *s) | |
124 | { | |
125 | FD_CLR (fd, s); | |
126 | } | |
127 | ||
128 | /* PROCEDURE FdIsSet (fd: INTEGER; SetOfFd) : BOOLEAN ; */ | |
129 | ||
130 | int | |
131 | Selective_FdIsSet (int fd, fd_set *s) | |
132 | { | |
133 | return FD_ISSET (fd, s); | |
134 | } | |
135 | ||
136 | /* GetTimeOfDay - fills in a record, Timeval, filled in with the | |
137 | current system time in seconds and microseconds. It returns zero | |
138 | (see man 3p gettimeofday) */ | |
139 | ||
140 | int | |
141 | Selective_GetTimeOfDay (struct timeval *t) | |
142 | { | |
143 | return gettimeofday (t, NULL); | |
144 | } | |
145 | #else | |
146 | ||
147 | void * | |
148 | Selective_InitTime (unsigned int sec, unsigned int usec) | |
149 | { | |
150 | return NULL; | |
151 | } | |
152 | ||
153 | void * | |
154 | Selective_KillTime (void *t) | |
155 | { | |
156 | return NULL; | |
157 | } | |
158 | ||
159 | void | |
160 | Selective_GetTime (struct timeval *t, unsigned int *sec, unsigned int *usec) | |
161 | { | |
162 | } | |
163 | ||
164 | void | |
165 | Selective_SetTime (struct timeval *t, unsigned int sec, unsigned int usec) | |
166 | { | |
167 | } | |
168 | ||
169 | fd_set * | |
170 | Selective_InitSet (void) | |
171 | { | |
172 | return NULL; | |
173 | } | |
174 | ||
175 | void | |
176 | Selective_FdZero (void *s) | |
177 | { | |
178 | } | |
179 | ||
180 | void | |
181 | Selective_FdSet (int fd, void *s) | |
182 | { | |
183 | } | |
184 | ||
185 | void | |
186 | Selective_FdClr (int fd, void *s) | |
187 | { | |
188 | } | |
189 | ||
190 | int | |
191 | Selective_FdIsSet (int fd, void *s) | |
192 | { | |
193 | return 0; | |
194 | } | |
195 | ||
196 | int | |
197 | Selective_GetTimeOfDay (struct timeval *t) | |
198 | { | |
199 | return -1; | |
200 | } | |
201 | #endif | |
202 | ||
203 | /* PROCEDURE MaxFdsPlusOne (a, b: File) : File ; */ | |
204 | ||
205 | int | |
206 | Selective_MaxFdsPlusOne (int a, int b) | |
207 | { | |
208 | if (a > b) | |
209 | return a + 1; | |
210 | else | |
211 | return b + 1; | |
212 | } | |
213 | ||
214 | /* PROCEDURE WriteCharRaw (fd: INTEGER; ch: CHAR) ; */ | |
215 | ||
216 | void | |
217 | Selective_WriteCharRaw (int fd, char ch) | |
218 | { | |
219 | write (fd, &ch, 1); | |
220 | } | |
221 | ||
222 | /* PROCEDURE ReadCharRaw (fd: INTEGER) : CHAR ; */ | |
223 | ||
224 | char | |
225 | Selective_ReadCharRaw (int fd) | |
226 | { | |
227 | char ch; | |
228 | ||
229 | read (fd, &ch, 1); | |
230 | return ch; | |
231 | } | |
232 | ||
233 | void | |
234 | _M2_Selective_init () | |
235 | { | |
236 | } | |
237 | ||
238 | void | |
239 | _M2_Selective_finish () | |
240 | { | |
241 | } |