tree-optimization/112450 - avoid AVX512 style masking for BImode masks
[official-gcc.git] / gcc / m2 / mc-boot-ch / GSelective.c
blobe41e848986d037eb0fd247ab60582065b5894445
1 /* GSelective.c provides access to select for Modula-2.
3 Copyright (C) 2016-2023 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius@glam.ac.uk>.
6 This file is part of GNU Modula-2.
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.
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.
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/>. */
22 /* implementation module in C. */
24 #include "config.h"
25 #include "system.h"
26 #include "ansidecl.h"
28 #include "gm2-libs-host.h"
30 #if defined(__cplusplus)
31 #define EXTERN extern "C"
32 #else
33 #define EXTERN
34 #endif
36 /* PROCEDURE Select (nooffds: CARDINAL; readfds, writefds, exceptfds:
37 SetOfFd; timeout: Timeval) : INTEGER ; */
39 #if defined(HAVE_SELECT)
40 EXTERN
41 int
42 Selective_Select (int nooffds, fd_set *readfds, fd_set *writefds,
43 fd_set *exceptfds, struct timeval *timeout)
45 return select (nooffds, readfds, writefds, exceptfds, timeout);
47 #else
48 EXTERN
49 int
50 Selective_Select (int nooffds, void *readfds, void *writefds, void *exceptfds,
51 void *timeout)
53 return 0;
55 #endif
57 /* PROCEDURE InitTime (sec, usec) : Timeval ; */
59 #if defined(HAVE_SELECT)
60 EXTERN
61 struct timeval *
62 Selective_InitTime (unsigned int sec, unsigned int usec)
64 struct timeval *t = (struct timeval *)malloc (sizeof (struct timeval));
66 t->tv_sec = (long int)sec;
67 t->tv_usec = (long int)usec;
68 return t;
71 EXTERN
72 void
73 Selective_GetTime (struct timeval *t, unsigned int *sec, unsigned int *usec)
75 *sec = (unsigned int)t->tv_sec;
76 *usec = (unsigned int)t->tv_usec;
79 EXTERN
80 void
81 Selective_SetTime (struct timeval *t, unsigned int sec, unsigned int usec)
83 t->tv_sec = sec;
84 t->tv_usec = usec;
87 /* PROCEDURE KillTime (t: Timeval) : Timeval ; */
89 EXTERN
90 struct timeval *
91 Selective_KillTime (struct timeval *t)
93 free (t);
94 return NULL;
97 /* PROCEDURE InitSet () : SetOfFd ; */
99 EXTERN
100 fd_set *
101 Selective_InitSet (void)
103 fd_set *s = (fd_set *)malloc (sizeof (fd_set));
105 return s;
108 /* PROCEDURE KillSet (s: SetOfFd) : SetOfFd ; */
110 EXTERN
111 fd_set *
112 Selective_KillSet (fd_set *s)
114 free (s);
115 return NULL;
118 /* PROCEDURE FdZero (s: SetOfFd) ; */
120 EXTERN
121 void
122 Selective_FdZero (fd_set *s)
124 FD_ZERO (s);
127 /* PROCEDURE Fd_Set (fd: INTEGER; SetOfFd) ; */
129 EXTERN
130 void
131 Selective_FdSet (int fd, fd_set *s)
133 FD_SET (fd, s);
136 /* PROCEDURE FdClr (fd: INTEGER; SetOfFd) ; */
138 EXTERN
139 void
140 Selective_FdClr (int fd, fd_set *s)
142 FD_CLR (fd, s);
145 /* PROCEDURE FdIsSet (fd: INTEGER; SetOfFd) : BOOLEAN ; */
147 EXTERN
149 Selective_FdIsSet (int fd, fd_set *s)
151 return FD_ISSET (fd, s);
154 /* GetTimeOfDay - fills in a record, Timeval, filled in with the
155 current system time in seconds and microseconds. It returns zero
156 (see man 3p gettimeofday) */
158 EXTERN
160 Selective_GetTimeOfDay (struct timeval *t)
162 return gettimeofday (t, NULL);
164 #else
166 EXTERN
167 void *
168 Selective_InitTime (unsigned int sec, unsigned int usec)
170 return NULL;
173 EXTERN
174 void *
175 Selective_KillTime (void *t)
177 return NULL;
180 EXTERN
181 void
182 Selective_GetTime (struct timeval *t, unsigned int *sec, unsigned int *usec)
186 EXTERN
187 void
188 Selective_SetTime (struct timeval *t, unsigned int sec, unsigned int usec)
192 EXTERN
193 fd_set *
194 Selective_InitSet (void)
196 return NULL;
199 EXTERN
200 void
201 Selective_FdZero (void *s)
205 EXTERN
206 void
207 Selective_FdSet (int fd, void *s)
211 EXTERN
212 void
213 Selective_FdClr (int fd, void *s)
217 EXTERN
219 Selective_FdIsSet (int fd, void *s)
221 return 0;
224 EXTERN
226 Selective_GetTimeOfDay (struct timeval *t)
228 return -1;
230 #endif
232 /* PROCEDURE MaxFdsPlusOne (a, b: File) : File ; */
234 EXTERN
236 Selective_MaxFdsPlusOne (int a, int b)
238 if (a > b)
239 return a + 1;
240 else
241 return b + 1;
244 /* PROCEDURE WriteCharRaw (fd: INTEGER; ch: CHAR) ; */
246 EXTERN
247 void
248 Selective_WriteCharRaw (int fd, char ch)
250 write (fd, &ch, 1);
253 /* PROCEDURE ReadCharRaw (fd: INTEGER) : CHAR ; */
255 EXTERN
256 char
257 Selective_ReadCharRaw (int fd)
259 char ch;
261 read (fd, &ch, 1);
262 return ch;
265 EXTERN
266 void
267 _M2_Selective_init ()
271 EXTERN
272 void
273 _M2_Selective_fini ()