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)
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. */
28 #include "gm2-libs-host.h"
30 #if defined(__cplusplus)
31 #define EXTERN extern "C"
36 /* PROCEDURE Select (nooffds: CARDINAL; readfds, writefds, exceptfds:
37 SetOfFd; timeout: Timeval) : INTEGER ; */
39 #if defined(HAVE_SELECT)
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
);
50 Selective_Select (int nooffds
, void *readfds
, void *writefds
, void *exceptfds
,
57 /* PROCEDURE InitTime (sec, usec) : Timeval ; */
59 #if defined(HAVE_SELECT)
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
;
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
;
81 Selective_SetTime (struct timeval
*t
, unsigned int sec
, unsigned int usec
)
87 /* PROCEDURE KillTime (t: Timeval) : Timeval ; */
91 Selective_KillTime (struct timeval
*t
)
97 /* PROCEDURE InitSet () : SetOfFd ; */
101 Selective_InitSet (void)
103 fd_set
*s
= (fd_set
*)malloc (sizeof (fd_set
));
108 /* PROCEDURE KillSet (s: SetOfFd) : SetOfFd ; */
112 Selective_KillSet (fd_set
*s
)
118 /* PROCEDURE FdZero (s: SetOfFd) ; */
122 Selective_FdZero (fd_set
*s
)
127 /* PROCEDURE Fd_Set (fd: INTEGER; SetOfFd) ; */
131 Selective_FdSet (int fd
, fd_set
*s
)
136 /* PROCEDURE FdClr (fd: INTEGER; SetOfFd) ; */
140 Selective_FdClr (int fd
, fd_set
*s
)
145 /* PROCEDURE FdIsSet (fd: INTEGER; SetOfFd) : BOOLEAN ; */
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) */
160 Selective_GetTimeOfDay (struct timeval
*t
)
162 return gettimeofday (t
, NULL
);
168 Selective_InitTime (unsigned int sec
, unsigned int usec
)
175 Selective_KillTime (void *t
)
182 Selective_GetTime (struct timeval
*t
, unsigned int *sec
, unsigned int *usec
)
188 Selective_SetTime (struct timeval
*t
, unsigned int sec
, unsigned int usec
)
194 Selective_InitSet (void)
201 Selective_FdZero (void *s
)
207 Selective_FdSet (int fd
, void *s
)
213 Selective_FdClr (int fd
, void *s
)
219 Selective_FdIsSet (int fd
, void *s
)
226 Selective_GetTimeOfDay (struct timeval
*t
)
232 /* PROCEDURE MaxFdsPlusOne (a, b: File) : File ; */
236 Selective_MaxFdsPlusOne (int a
, int b
)
244 /* PROCEDURE WriteCharRaw (fd: INTEGER; ch: CHAR) ; */
248 Selective_WriteCharRaw (int fd
, char ch
)
253 /* PROCEDURE ReadCharRaw (fd: INTEGER) : CHAR ; */
257 Selective_ReadCharRaw (int fd
)
267 _M2_Selective_init ()
273 _M2_Selective_fini ()