123a0898aSmrg/* 223a0898aSmrg * Copyright 1990 Network Computing Devices; 323a0898aSmrg * Portions Copyright 1987 by Digital Equipment Corporation 423a0898aSmrg */ 523a0898aSmrg 623a0898aSmrg/* 723a0898aSmrg 823a0898aSmrgCopyright 1987, 1994, 1998 The Open Group 923a0898aSmrg 1023a0898aSmrgPermission to use, copy, modify, distribute, and sell this software and its 1123a0898aSmrgdocumentation for any purpose is hereby granted without fee, provided that 1223a0898aSmrgthe above copyright notice appear in all copies and that both that 1323a0898aSmrgcopyright notice and this permission notice appear in supporting 1423a0898aSmrgdocumentation. 1523a0898aSmrg 1623a0898aSmrgThe above copyright notice and this permission notice shall be included 1723a0898aSmrgin all copies or substantial portions of the Software. 1823a0898aSmrg 1923a0898aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 2023a0898aSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2123a0898aSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 2223a0898aSmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 2323a0898aSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 2423a0898aSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2523a0898aSmrgOTHER DEALINGS IN THE SOFTWARE. 2623a0898aSmrg 2723a0898aSmrgExcept as contained in this notice, the name of The Open Group shall 2823a0898aSmrgnot be used in advertising or otherwise to promote the sale, use or 2923a0898aSmrgother dealings in this Software without prior written authorization 3023a0898aSmrgfrom The Open Group. 3123a0898aSmrg 3223a0898aSmrg*/ 3323a0898aSmrg 3423a0898aSmrg/* 3523a0898aSmrg * FSlib networking & os include file 3623a0898aSmrg */ 3723a0898aSmrg 3823a0898aSmrg#include <X11/Xtrans/Xtrans.h> 3923a0898aSmrg 4023a0898aSmrg#ifndef WIN32 4123a0898aSmrg 4223a0898aSmrg/* 4323a0898aSmrg * makedepend screws up on #undef OPEN_MAX, so we define a new symbol 4423a0898aSmrg */ 4523a0898aSmrg 46121a5469Smrg# ifndef FONT_OPEN_MAX 47121a5469Smrg 48121a5469Smrg# ifdef _POSIX_SOURCE 49121a5469Smrg# include <limits.h> 50121a5469Smrg# else 51121a5469Smrg# define _POSIX_SOURCE 52121a5469Smrg# include <limits.h> 53121a5469Smrg# undef _POSIX_SOURCE 54121a5469Smrg# endif 55121a5469Smrg# ifndef SIZE_MAX 56121a5469Smrg# ifdef ULONG_MAX 57121a5469Smrg# define SIZE_MAX ULONG_MAX 58121a5469Smrg# else 59121a5469Smrg# define SIZE_MAX UINT_MAX 60121a5469Smrg# endif 61121a5469Smrg# endif 62121a5469Smrg# ifndef OPEN_MAX 63121a5469Smrg# if defined(SVR4) 64121a5469Smrg# define OPEN_MAX 256 65121a5469Smrg# else 66121a5469Smrg# include <sys/param.h> 67121a5469Smrg# ifndef OPEN_MAX 68121a5469Smrg# ifdef __OSF1__ 69121a5469Smrg# define OPEN_MAX 256 70121a5469Smrg# else 71121a5469Smrg# ifdef NOFILE 72121a5469Smrg# define OPEN_MAX NOFILE 73121a5469Smrg# else 74121a5469Smrg# define OPEN_MAX NOFILES_MAX 75121a5469Smrg# endif 76121a5469Smrg# endif 77121a5469Smrg# endif 78121a5469Smrg# endif 79121a5469Smrg# endif 80121a5469Smrg 81121a5469Smrg# if OPEN_MAX > 256 82121a5469Smrg# define FONT_OPEN_MAX 256 83121a5469Smrg# else 84121a5469Smrg# define FONT_OPEN_MAX OPEN_MAX 85121a5469Smrg# endif 86121a5469Smrg 87121a5469Smrg# endif /* FONT_OPEN_MAX */ 88121a5469Smrg 89121a5469Smrg# ifdef WORD64 90121a5469Smrg# define NMSKBITS 64 9123a0898aSmrg# else 92121a5469Smrg# define NMSKBITS 32 9323a0898aSmrg# endif 9423a0898aSmrg 95121a5469Smrg# define MSKCNT ((FONT_OPEN_MAX + NMSKBITS - 1) / NMSKBITS) 9623a0898aSmrg 9723a0898aSmrgtypedef unsigned long FdSet[MSKCNT]; 9823a0898aSmrgtypedef FdSet FdSetPtr; 9923a0898aSmrg 100121a5469Smrg# if (MSKCNT==1) 101121a5469Smrg# define BITMASK(i) (1 << (i)) 102121a5469Smrg# define MASKIDX(i) 0 103121a5469Smrg# endif 10423a0898aSmrg 105121a5469Smrg# if (MSKCNT>1) 106121a5469Smrg# define BITMASK(i) (1 << ((i) & (NMSKBITS - 1))) 107121a5469Smrg# define MASKIDX(i) ((i) / NMSKBITS) 108121a5469Smrg# endif 10923a0898aSmrg 110121a5469Smrg# define MASKWORD(buf, i) buf[MASKIDX(i)] 111121a5469Smrg# define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i) 112121a5469Smrg# define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i) 113121a5469Smrg# define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i)) 114121a5469Smrg 115121a5469Smrg# if (MSKCNT==1) 116121a5469Smrg# define COPYBITS(src, dst) dst[0] = src[0] 117121a5469Smrg# define CLEARBITS(buf) buf[0] = 0 118121a5469Smrg# define MASKANDSETBITS(dst, b1, b2) dst[0] = (b1[0] & b2[0]) 119121a5469Smrg# define ORBITS(dst, b1, b2) dst[0] = (b1[0] | b2[0]) 120121a5469Smrg# define UNSETBITS(dst, b1) (dst[0] &= ~b1[0]) 121121a5469Smrg# define ANYSET(src) (src[0]) 122121a5469Smrg# endif 12323a0898aSmrg 124121a5469Smrg# if (MSKCNT==2) 125121a5469Smrg# define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; } 126121a5469Smrg# define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; } 127121a5469Smrg# define MASKANDSETBITS(dst, b1, b2) {\ 12823a0898aSmrg dst[0] = (b1[0] & b2[0]);\ 12923a0898aSmrg dst[1] = (b1[1] & b2[1]); } 130121a5469Smrg# define ORBITS(dst, b1, b2) {\ 13123a0898aSmrg dst[0] = (b1[0] | b2[0]);\ 13223a0898aSmrg dst[1] = (b1[1] | b2[1]); } 133121a5469Smrg# define UNSETBITS(dst, b1) {\ 13423a0898aSmrg dst[0] &= ~b1[0]; \ 13523a0898aSmrg dst[1] &= ~b1[1]; } 136121a5469Smrg# define ANYSET(src) (src[0] || src[1]) 137121a5469Smrg# endif 13823a0898aSmrg 139121a5469Smrg# if (MSKCNT==3) 140121a5469Smrg# define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; \ 14123a0898aSmrg dst[2] = src[2]; } 142121a5469Smrg# define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; buf[2] = 0; } 143121a5469Smrg# define MASKANDSETBITS(dst, b1, b2) {\ 14423a0898aSmrg dst[0] = (b1[0] & b2[0]);\ 14523a0898aSmrg dst[1] = (b1[1] & b2[1]);\ 14623a0898aSmrg dst[2] = (b1[2] & b2[2]); } 147121a5469Smrg# define ORBITS(dst, b1, b2) {\ 14823a0898aSmrg dst[0] = (b1[0] | b2[0]);\ 14923a0898aSmrg dst[1] = (b1[1] | b2[1]);\ 15023a0898aSmrg dst[2] = (b1[2] | b2[2]); } 151121a5469Smrg# define UNSETBITS(dst, b1) {\ 15223a0898aSmrg dst[0] &= ~b1[0]; \ 15323a0898aSmrg dst[1] &= ~b1[1]; \ 15423a0898aSmrg dst[2] &= ~b1[2]; } 155121a5469Smrg# define ANYSET(src) (src[0] || src[1] || src[2]) 156121a5469Smrg# endif 15723a0898aSmrg 158121a5469Smrg# if (MSKCNT==4) 159121a5469Smrg# define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; \ 16023a0898aSmrg dst[2] = src[2]; dst[3] = src[3] 161121a5469Smrg# define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0; buf[3] = 0 162121a5469Smrg# define MASKANDSETBITS(dst, b1, b2) \ 16323a0898aSmrg dst[0] = (b1[0] & b2[0]);\ 16423a0898aSmrg dst[1] = (b1[1] & b2[1]);\ 16523a0898aSmrg dst[2] = (b1[2] & b2[2]);\ 16623a0898aSmrg dst[3] = (b1[3] & b2[3]) 167121a5469Smrg# define ORBITS(dst, b1, b2) \ 16823a0898aSmrg dst[0] = (b1[0] | b2[0]);\ 16923a0898aSmrg dst[1] = (b1[1] | b2[1]);\ 17023a0898aSmrg dst[2] = (b1[2] | b2[2]);\ 17123a0898aSmrg dst[3] = (b1[3] | b2[3]) 172121a5469Smrg# define UNSETBITS(dst, b1) \ 17323a0898aSmrg dst[0] &= ~b1[0]; \ 17423a0898aSmrg dst[1] &= ~b1[1]; \ 17523a0898aSmrg dst[2] &= ~b1[2]; \ 17623a0898aSmrg dst[3] &= ~b1[3] 177121a5469Smrg# define ANYSET(src) (src[0] || src[1] || src[2] || src[3]) 178121a5469Smrg# endif 17923a0898aSmrg 180121a5469Smrg# if (MSKCNT>4) 181121a5469Smrg# define COPYBITS(src, dst) memmove((caddr_t) dst, (caddr_t) src,\ 18223a0898aSmrg MSKCNT*sizeof(long)) 183121a5469Smrg# define CLEARBITS(buf) bzero((caddr_t) buf, MSKCNT*sizeof(long)) 184121a5469Smrg# define MASKANDSETBITS(dst, b1, b2) \ 18523a0898aSmrg { int cri; \ 18623a0898aSmrg for (cri=MSKCNT; --cri>=0; ) \ 18723a0898aSmrg dst[cri] = (b1[cri] & b2[cri]); } 188121a5469Smrg# define ORBITS(dst, b1, b2) \ 18923a0898aSmrg { int cri; \ 19023a0898aSmrg for (cri=MSKCNT; --cri>=0; ) \ 19123a0898aSmrg dst[cri] = (b1[cri] | b2[cri]); } 192121a5469Smrg# define UNSETBITS(dst, b1) \ 19323a0898aSmrg { int cri; \ 19423a0898aSmrg for (cri=MSKCNT; --cri>=0; ) \ 19523a0898aSmrg dst[cri] &= ~b1[cri]; } 196121a5469Smrg# if (MSKCNT==8) 197121a5469Smrg# define ANYSET(src) (src[0] || src[1] || src[2] || src[3] || \ 19823a0898aSmrg src[4] || src[5] || src[6] || src[7]) 199121a5469Smrg# endif 200121a5469Smrg# endif 20123a0898aSmrg 20223a0898aSmrg#else /* not WIN32 */ 20323a0898aSmrg 204121a5469Smrg# include <X11/Xwinsock.h> 205121a5469Smrg# include <X11/Xw32defs.h> 20623a0898aSmrg 20723a0898aSmrgtypedef fd_set FdSet; 20823a0898aSmrgtypedef FdSet *FdSetPtr; 20923a0898aSmrg 210121a5469Smrg# define CLEARBITS(set) FD_ZERO(&set) 211121a5469Smrg# define BITSET(set,s) FD_SET(s,&set) 212121a5469Smrg# define BITCLEAR(set,s) FD_CLR(s,&set) 213121a5469Smrg# define GETBIT(set,s) FD_ISSET(s,&set) 214121a5469Smrg# define ANYSET(set) set->fd_count 21523a0898aSmrg 21623a0898aSmrg#endif 217