aix: Fix building fat library for AIX
[official-gcc.git] / gcc / m2 / gm2-libs-ch / Selective.c
blob14695b91b2cb3b17659e503ae1a1cfa827aa8abc
1 /* Selective.c provide access to timeval and select.
3 Copyright (C) 2005-2024 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 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
27 #include "config.h"
28 #include "system.h"
29 #include "ansidecl.h"
31 #include "gm2-libs-host.h"
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
37 #if defined(HAVE_SELECT)
38 # define FDSET_T fd_set
39 #else
40 # define FDSET_T void
41 #endif
44 #if defined(HAVE_SELECT)
45 int Selective_Select (int nooffds,
46 fd_set *readfds,
47 fd_set *writefds,
48 fd_set *exceptfds,
49 struct timeval *timeout)
51 return select (nooffds, readfds, writefds, exceptfds, timeout);
53 #else
54 int Selective_Select (int nooffds,
55 void *readfds,
56 void *writefds,
57 void *exceptfds,
58 void *timeout)
60 return 0;
62 #endif
64 /* InitTime initialises a timeval structure and returns a pointer to it. */
66 #if defined(HAVE_SELECT)
67 struct timeval *Selective_InitTime (unsigned int sec, unsigned int usec)
69 struct timeval *t = (struct timeval *) malloc (sizeof (struct timeval));
71 t->tv_sec = (long int) sec;
72 t->tv_usec = (long int) usec;
73 return t;
76 void Selective_GetTime (struct timeval *t,
77 unsigned int *sec, unsigned int *usec)
79 *sec = (unsigned int) t->tv_sec;
80 *usec = (unsigned int) t->tv_usec;
83 void Selective_SetTime (struct timeval *t,
84 unsigned int sec, unsigned int usec)
86 t->tv_sec = sec;
87 t->tv_usec = usec;
90 /* KillTime frees the timeval structure and returns NULL. */
92 struct timeval *Selective_KillTime (struct timeval *t)
94 free (t);
95 return NULL;
98 /* InitSet returns a pointer to a FD_SET. */
100 fd_set *Selective_InitSet (void)
102 fd_set *s = (fd_set *) malloc (sizeof (fd_set));
104 return s;
107 /* KillSet frees the FD_SET and returns NULL. */
109 fd_set *Selective_KillSet (fd_set *s)
111 free (s);
112 return NULL;
115 /* FdZero generate an empty set. */
117 void Selective_FdZero (fd_set *s)
119 FD_ZERO (s);
122 /* FS_Set include an element, fd, into set, s. */
124 void Selective_FdSet (int fd, fd_set *s)
126 FD_SET (fd, s);
130 /* FdClr exclude an element, fd, from the set, s. */
132 void Selective_FdClr (int fd, fd_set *s)
134 FD_CLR (fd, s);
138 /* FdIsSet return TRUE if, fd, is present in set, s. */
140 int Selective_FdIsSet (int fd, fd_set *s)
142 return FD_ISSET (fd, s);
145 /* GetTimeOfDay fills in a record, Timeval, filled in with the
146 current system time in seconds and microseconds.
147 It returns zero (see man 3p gettimeofday). */
149 int Selective_GetTimeOfDay (struct timeval *t)
151 return gettimeofday (t, NULL);
153 #else
155 void *Selective_InitTime (unsigned int sec, unsigned int usec)
157 return NULL;
160 void *Selective_KillTime (void *t)
162 return NULL;
165 void Selective_GetTime (struct timeval *t,
166 unsigned int *sec, unsigned int *usec)
170 void Selective_SetTime (struct timeval *t,
171 unsigned int sec, unsigned int usec)
175 fd_set *Selective_InitSet (void)
177 return NULL;
180 void Selective_FdZero (void *s)
184 void Selective_FdSet (int fd, void *s)
188 void Selective_FdClr (int fd, void *s)
192 int Selective_FdIsSet (int fd, void *s)
194 return 0;
197 int Selective_GetTimeOfDay (struct timeval *t)
199 return -1;
201 #endif
204 /* MaxFdsPlusOne returns max (a + 1, b + 1). */
206 int Selective_MaxFdsPlusOne (int a, int b)
208 if (a > b)
209 return a+1;
210 else
211 return b+1;
215 /* WriteCharRaw writes a single character to the file descriptor. */
217 void Selective_WriteCharRaw (int fd, char ch)
219 write (fd, &ch, 1);
223 /* ReadCharRaw read and return a single char from file descriptor, fd. */
225 char Selective_ReadCharRaw (int fd)
227 char ch;
229 read (fd, &ch, 1);
230 return ch;
234 void
235 _M2_Selective_init ()
239 void
240 _M2_Selective_finish ()
244 #ifdef __cplusplus
246 #endif