1
/* $XdotOrg: xc/lib/FS/FSlibos.h,v 1.3 2005/06/09 15:52:02 ago Exp $ */
2
/* $Xorg: FSlibos.h,v 1.4 2001/02/09 02:03:25 xorgcvs Exp $ */
4
/* @(#)FSlibos.h 4.1 91/05/02
5
* Copyright 1990 Network Computing Devices;
6
* Portions Copyright 1987 by Digital Equipment Corporation
8
* Permission to use, copy, modify, distribute, and sell this software
9
* and its documentation for any purpose is hereby granted without fee,
10
* provided that the above copyright notice appear in all copies and
11
* that both that copyright notice and this permission notice appear
12
* in supporting documentation, and that the names of Network Computing
13
* Devices or Digital not be used in advertising or publicity pertaining
14
* to distribution of the software without specific, written prior
15
* permission. Network Computing Devices or Digital make no representations
16
* about the suitability of this software for any purpose. It is provided
17
* "as is" without express or implied warranty.
19
* NETWORK COMPUTING DEVICES AND DIGITAL DISCLAIM ALL WARRANTIES WITH
20
* REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
21
* MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES
22
* OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
23
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
24
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
25
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
31
Copyright 1987, 1994, 1998 The Open Group
33
Permission to use, copy, modify, distribute, and sell this software and its
34
documentation for any purpose is hereby granted without fee, provided that
35
the above copyright notice appear in all copies and that both that
36
copyright notice and this permission notice appear in supporting
39
The above copyright notice and this permission notice shall be included in
40
all copies or substantial portions of the Software.
42
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
46
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
47
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49
Except as contained in this notice, the name of The Open Group shall not be
50
used in advertising or otherwise to promote the sale, use or other dealings
51
in this Software without prior written authorization from The Open Group.
54
/* $XFree86: xc/lib/FS/FSlibos.h,v 3.10 2003/09/01 20:50:10 herrb Exp $ */
57
* FSlib networking & os include file
60
#include <X11/Xfuncs.h>
61
#include <X11/Xosdefs.h>
65
#if defined(SCO) || defined(__USLC__)
66
#include <stdint.h> /* For SIZE_MAX */
70
* makedepend screws up on #undef OPEN_MAX, so we define a new symbol
86
# define SIZE_MAX ULONG_MAX
88
# define SIZE_MAX UINT_MAX
95
#include <sys/param.h>
101
#define OPEN_MAX NOFILE
103
#if !defined(__UNIXOS2__) && !defined(__QNX__)
105
#define OPEN_MAX (sysconf(_SC_OPEN_MAX))
107
#define OPEN_MAX NOFILES_MAX
109
#else /* !__UNIXOS2__ && !__QNX__ */
111
#endif /* __UNIXOS2__ */
119
#define FS_OPEN_MAX 256
122
#define FS_OPEN_MAX 256
124
#define FS_OPEN_MAX OPEN_MAX
128
#endif /* FS_OPEN_MAX */
130
/* Utek leaves kernel macros around in include files (bleah) */
142
#define MSKCNT ((FS_OPEN_MAX + NMSKBITS - 1) / NMSKBITS)
145
typedef unsigned int FdSet[MSKCNT];
147
typedef unsigned long FdSet[MSKCNT];
151
#define BITMASK(i) (1 << (i))
156
#define BITMASK(i) (1 << ((i) & (NMSKBITS - 1)))
157
#define MASKIDX(i) ((i) / NMSKBITS)
160
#define MASKWORD(buf, i) buf[MASKIDX(i)]
161
#define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i)
162
#define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i)
163
#define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i))
166
#define COPYBITS(src, dst) dst[0] = src[0]
167
#define CLEARBITS(buf) buf[0] = 0
168
#define MASKANDSETBITS(dst, b1, b2) dst[0] = (b1[0] & b2[0])
169
#define ORBITS(dst, b1, b2) dst[0] = (b1[0] | b2[0])
170
#define UNSETBITS(dst, b1) (dst[0] &= ~b1[0])
171
#define _FSANYSET(src) (src[0])
175
#define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; }
176
#define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; }
177
#define MASKANDSETBITS(dst, b1, b2) {\
178
dst[0] = (b1[0] & b2[0]);\
179
dst[1] = (b1[1] & b2[1]); }
180
#define ORBITS(dst, b1, b2) {\
181
dst[0] = (b1[0] | b2[0]);\
182
dst[1] = (b1[1] | b2[1]); }
183
#define UNSETBITS(dst, b1) {\
186
#define _FSANYSET(src) (src[0] || src[1])
190
#define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; \
192
#define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; buf[2] = 0; }
193
#define MASKANDSETBITS(dst, b1, b2) {\
194
dst[0] = (b1[0] & b2[0]);\
195
dst[1] = (b1[1] & b2[1]);\
196
dst[2] = (b1[2] & b2[2]); }
197
#define ORBITS(dst, b1, b2) {\
198
dst[0] = (b1[0] | b2[0]);\
199
dst[1] = (b1[1] | b2[1]);\
200
dst[2] = (b1[2] | b2[2]); }
201
#define UNSETBITS(dst, b1) {\
205
#define _FSANYSET(src) (src[0] || src[1] || src[2])
209
#define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; \
210
dst[2] = src[2]; dst[3] = src[3]
211
#define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0; buf[3] = 0
212
#define MASKANDSETBITS(dst, b1, b2) \
213
dst[0] = (b1[0] & b2[0]);\
214
dst[1] = (b1[1] & b2[1]);\
215
dst[2] = (b1[2] & b2[2]);\
216
dst[3] = (b1[3] & b2[3])
217
#define ORBITS(dst, b1, b2) \
218
dst[0] = (b1[0] | b2[0]);\
219
dst[1] = (b1[1] | b2[1]);\
220
dst[2] = (b1[2] | b2[2]);\
221
dst[3] = (b1[3] | b2[3])
222
#define UNSETBITS(dst, b1) \
227
#define _FSANYSET(src) (src[0] || src[1] || src[2] || src[3])
231
#define COPYBITS(src, dst) bcopy((caddr_t) src, (caddr_t) dst, sizeof(FdSet))
232
#define CLEARBITS(buf) bzero((caddr_t) buf, sizeof(FdSet))
233
#define MASKANDSETBITS(dst, b1, b2) \
235
for (cri=0; cri<MSKCNT; cri++) \
236
dst[cri] = (b1[cri] & b2[cri]) }
237
#define ORBITS(dst, b1, b2) \
239
for (cri=0; cri<MSKCNT; cri++) \
240
dst[cri] = (b1[cri] | b2[cri]) }
241
#define UNSETBITS(dst, b1) \
243
for (cri=0; cri<MSKCNT; cri++) \
244
dst[cri] &= ~b1[cri]; }
246
#define _FSANYSET(src) (src[0] || src[1] || src[2] || src[3] || \
247
src[4] || src[5] || src[6] || src[7])
250
* If MSKCNT>4 and not 8, then _FSANYSET is a routine defined in FSlibInt.c.
252
* #define _FSANYSET(src) (src[0] || src[1] || src[2] || src[3] || src[4] ...)
259
#include <X11/Xwinsock.h>
260
#include <X11/Xw32defs.h>
262
typedef fd_set FdSet;
264
#define CLEARBITS(set) FD_ZERO(&set)
265
#define BITSET(set,s) FD_SET(s,&set)
266
#define _FSANYSET(set) set.fd_count
270
#include <X11/Xtrans/Xtrans.h>
275
* The following definitions can be used for locking requests in multi-threaded
278
#define LockDisplay(dis)
279
#define LockMutex(mutex)
280
#define UnlockMutex(mutex)
281
#define UnlockDisplay(dis)
282
#define FSfree(ptr) free((ptr))
286
* Note that some machines do not return a valid pointer for malloc(0), in
287
* which case we provide an alternate under the control of the
288
* define MALLOC_0_RETURNS_NULL. This is necessary because some
289
* FSlib code expects malloc(0) to return a valid pointer to storage.
292
#ifdef MALLOC_0_RETURNS_NULL
293
#define FSmalloc(size) malloc(((size) > 0 ? (size) : 1))
294
#define FSrealloc(ptr, size) realloc((ptr), ((size) > 0 ? (size) : 1))
295
#define FScalloc(nelem, elsize) calloc(((nelem) > 0 ? (nelem) : 1), (elsize))
299
#define FSmalloc(size) malloc((size))
300
#define FSrealloc(ptr, size) realloc((ptr), (size))
301
#define FScalloc(nelem, elsize) calloc((nelem), (elsize))
305
* ReadvFromServer and WritevToSever use struct iovec, normally found
306
* in Berkeley systems in <sys/uio.h>. See the readv(2) and writev(2)
307
* manual pages for details.
317
#if defined(USG) && !defined(CRAY) && !defined(umips) && !defined(MOTOROLA)
320
struct timeval { /* BSD has in <sys/time.h> */
325
#endif /* __TIMEVAL__ */
327
#endif /* not CRAY or umips */
332
#define SearchString(string, char) index((string), (char))