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