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