fslibos.h revision 6a46240f
1/* 2 * Copyright 1990 Network Computing Devices; 3 * Portions Copyright 1987 by Digital Equipment Corporation 4 */ 5 6/* 7 8Copyright 1987, 1994, 1998 The Open Group 9 10Permission to use, copy, modify, distribute, and sell this software and its 11documentation for any purpose is hereby granted without fee, provided that 12the above copyright notice appear in all copies and that both that 13copyright notice and this permission notice appear in supporting 14documentation. 15 16The above copyright notice and this permission notice shall be included 17in all copies or substantial portions of the Software. 18 19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 23OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 24ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 25OTHER DEALINGS IN THE SOFTWARE. 26 27Except as contained in this notice, the name of The Open Group shall 28not be used in advertising or otherwise to promote the sale, use or 29other dealings in this Software without prior written authorization 30from The Open Group. 31 32*/ 33 34/* 35 * FSlib networking & os include file 36 */ 37 38#include <X11/Xtrans/Xtrans.h> 39 40#ifndef WIN32 41 42/* 43 * makedepend screws up on #undef OPEN_MAX, so we define a new symbol 44 */ 45 46# ifndef FONT_OPEN_MAX 47 48# ifdef _POSIX_SOURCE 49# include <limits.h> 50# else 51# define _POSIX_SOURCE 52# include <limits.h> 53# undef _POSIX_SOURCE 54# endif 55# ifndef SIZE_MAX 56# ifdef ULONG_MAX 57# define SIZE_MAX ULONG_MAX 58# else 59# define SIZE_MAX UINT_MAX 60# endif 61# endif 62# ifndef OPEN_MAX 63# if defined(SVR4) 64# define OPEN_MAX 256 65# else 66# include <sys/param.h> 67# ifndef OPEN_MAX 68# ifdef NOFILE 69# define OPEN_MAX NOFILE 70# else 71# define OPEN_MAX NOFILES_MAX 72# endif 73# endif 74# endif 75# endif 76 77# if OPEN_MAX > 256 78# define FONT_OPEN_MAX 256 79# else 80# define FONT_OPEN_MAX OPEN_MAX 81# endif 82 83# endif /* FONT_OPEN_MAX */ 84 85# ifdef WORD64 86# define NMSKBITS 64 87# else 88# define NMSKBITS 32 89# endif 90 91# define MSKCNT ((FONT_OPEN_MAX + NMSKBITS - 1) / NMSKBITS) 92 93typedef unsigned long FdSet[MSKCNT]; 94typedef FdSet FdSetPtr; 95 96# if (MSKCNT==1) 97# define BITMASK(i) (1 << (i)) 98# define MASKIDX(i) 0 99# endif 100 101# if (MSKCNT>1) 102# define BITMASK(i) (1 << ((i) & (NMSKBITS - 1))) 103# define MASKIDX(i) ((i) / NMSKBITS) 104# endif 105 106# define MASKWORD(buf, i) buf[MASKIDX(i)] 107# define BITSET(buf, i) MASKWORD(buf, i) |= BITMASK(i) 108# define BITCLEAR(buf, i) MASKWORD(buf, i) &= ~BITMASK(i) 109# define GETBIT(buf, i) (MASKWORD(buf, i) & BITMASK(i)) 110 111# if (MSKCNT==1) 112# define COPYBITS(src, dst) dst[0] = src[0] 113# define CLEARBITS(buf) buf[0] = 0 114# define MASKANDSETBITS(dst, b1, b2) dst[0] = (b1[0] & b2[0]) 115# define ORBITS(dst, b1, b2) dst[0] = (b1[0] | b2[0]) 116# define UNSETBITS(dst, b1) (dst[0] &= ~b1[0]) 117# define ANYSET(src) (src[0]) 118# endif 119 120# if (MSKCNT==2) 121# define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; } 122# define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; } 123# define MASKANDSETBITS(dst, b1, b2) {\ 124 dst[0] = (b1[0] & b2[0]);\ 125 dst[1] = (b1[1] & b2[1]); } 126# define ORBITS(dst, b1, b2) {\ 127 dst[0] = (b1[0] | b2[0]);\ 128 dst[1] = (b1[1] | b2[1]); } 129# define UNSETBITS(dst, b1) {\ 130 dst[0] &= ~b1[0]; \ 131 dst[1] &= ~b1[1]; } 132# define ANYSET(src) (src[0] || src[1]) 133# endif 134 135# if (MSKCNT==3) 136# define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; \ 137 dst[2] = src[2]; } 138# define CLEARBITS(buf) { buf[0] = 0; buf[1] = 0; buf[2] = 0; } 139# define MASKANDSETBITS(dst, b1, b2) {\ 140 dst[0] = (b1[0] & b2[0]);\ 141 dst[1] = (b1[1] & b2[1]);\ 142 dst[2] = (b1[2] & b2[2]); } 143# define ORBITS(dst, b1, b2) {\ 144 dst[0] = (b1[0] | b2[0]);\ 145 dst[1] = (b1[1] | b2[1]);\ 146 dst[2] = (b1[2] | b2[2]); } 147# define UNSETBITS(dst, b1) {\ 148 dst[0] &= ~b1[0]; \ 149 dst[1] &= ~b1[1]; \ 150 dst[2] &= ~b1[2]; } 151# define ANYSET(src) (src[0] || src[1] || src[2]) 152# endif 153 154# if (MSKCNT==4) 155# define COPYBITS(src, dst) dst[0] = src[0]; dst[1] = src[1]; \ 156 dst[2] = src[2]; dst[3] = src[3] 157# define CLEARBITS(buf) buf[0] = 0; buf[1] = 0; buf[2] = 0; buf[3] = 0 158# define MASKANDSETBITS(dst, b1, b2) \ 159 dst[0] = (b1[0] & b2[0]);\ 160 dst[1] = (b1[1] & b2[1]);\ 161 dst[2] = (b1[2] & b2[2]);\ 162 dst[3] = (b1[3] & b2[3]) 163# define ORBITS(dst, b1, b2) \ 164 dst[0] = (b1[0] | b2[0]);\ 165 dst[1] = (b1[1] | b2[1]);\ 166 dst[2] = (b1[2] | b2[2]);\ 167 dst[3] = (b1[3] | b2[3]) 168# define UNSETBITS(dst, b1) \ 169 dst[0] &= ~b1[0]; \ 170 dst[1] &= ~b1[1]; \ 171 dst[2] &= ~b1[2]; \ 172 dst[3] &= ~b1[3] 173# define ANYSET(src) (src[0] || src[1] || src[2] || src[3]) 174# endif 175 176# if (MSKCNT>4) 177# define COPYBITS(src, dst) memmove((caddr_t) dst, (caddr_t) src,\ 178 MSKCNT*sizeof(long)) 179# define CLEARBITS(buf) bzero((caddr_t) buf, MSKCNT*sizeof(long)) 180# define MASKANDSETBITS(dst, b1, b2) \ 181 { int cri; \ 182 for (cri=MSKCNT; --cri>=0; ) \ 183 dst[cri] = (b1[cri] & b2[cri]); } 184# define ORBITS(dst, b1, b2) \ 185 { int cri; \ 186 for (cri=MSKCNT; --cri>=0; ) \ 187 dst[cri] = (b1[cri] | b2[cri]); } 188# define UNSETBITS(dst, b1) \ 189 { int cri; \ 190 for (cri=MSKCNT; --cri>=0; ) \ 191 dst[cri] &= ~b1[cri]; } 192# if (MSKCNT==8) 193# define ANYSET(src) (src[0] || src[1] || src[2] || src[3] || \ 194 src[4] || src[5] || src[6] || src[7]) 195# endif 196# endif 197 198#else /* not WIN32 */ 199 200# include <X11/Xwinsock.h> 201# include <X11/Xw32defs.h> 202 203typedef fd_set FdSet; 204typedef FdSet *FdSetPtr; 205 206# define CLEARBITS(set) FD_ZERO(&set) 207# define BITSET(set,s) FD_SET(s,&set) 208# define BITCLEAR(set,s) FD_CLR(s,&set) 209# define GETBIT(set,s) FD_ISSET(s,&set) 210# define ANYSET(set) set->fd_count 211 212#endif 213