~ubuntu-branches/ubuntu/precise/libfs/precise-security

« back to all changes in this revision

Viewing changes to src/FSlibos.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Stone
  • Date: 2005-07-23 00:15:32 UTC
  • Revision ID: james.westby@ubuntu.com-20050723001532-1n80puvkrct21vfl
Tags: upstream-3.0.0
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 $ */
 
3
 
 
4
/* @(#)FSlibos.h        4.1     91/05/02
 
5
 * Copyright 1990 Network Computing Devices;
 
6
 * Portions Copyright 1987 by Digital Equipment Corporation
 
7
 *
 
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.
 
18
 *
 
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 
 
26
 * SOFTWARE.
 
27
 */
 
28
 
 
29
/*
 
30
 
 
31
Copyright 1987, 1994, 1998  The Open Group
 
32
 
 
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
 
37
documentation.
 
38
 
 
39
The above copyright notice and this permission notice shall be included in
 
40
all copies or substantial portions of the Software.
 
41
 
 
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.
 
48
 
 
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.
 
52
 
 
53
*/
 
54
/* $XFree86: xc/lib/FS/FSlibos.h,v 3.10 2003/09/01 20:50:10 herrb Exp $ */
 
55
 
 
56
/*
 
57
 * FSlib networking & os include file
 
58
 */
 
59
 
 
60
#include <X11/Xfuncs.h>
 
61
#include <X11/Xosdefs.h>
 
62
 
 
63
#ifndef WIN32
 
64
 
 
65
#if defined(SCO) || defined(__USLC__)
 
66
#include <stdint.h>     /* For SIZE_MAX */
 
67
#endif
 
68
 
 
69
/*
 
70
 * makedepend screws up on #undef OPEN_MAX, so we define a new symbol
 
71
 */
 
72
 
 
73
#ifndef FS_OPEN_MAX
 
74
 
 
75
#ifndef X_NOT_POSIX
 
76
#ifdef _POSIX_SOURCE
 
77
#include <limits.h>
 
78
#else
 
79
#define _POSIX_SOURCE
 
80
#include <limits.h>
 
81
#undef _POSIX_SOURCE
 
82
#endif
 
83
#endif
 
84
#ifndef SIZE_MAX
 
85
# ifdef ULONG_MAX
 
86
#  define SIZE_MAX ULONG_MAX
 
87
# else 
 
88
#  define SIZE_MAX UINT_MAX
 
89
# endif
 
90
#endif
 
91
#ifndef OPEN_MAX
 
92
#ifdef SVR4
 
93
#define OPEN_MAX 256
 
94
#else
 
95
#include <sys/param.h>
 
96
#ifndef OPEN_MAX
 
97
#ifdef __OSF1__
 
98
#define OPEN_MAX 256
 
99
#else
 
100
#ifdef NOFILE
 
101
#define OPEN_MAX NOFILE
 
102
#else
 
103
#if !defined(__UNIXOS2__) && !defined(__QNX__)
 
104
#ifdef __GNU__
 
105
#define OPEN_MAX (sysconf(_SC_OPEN_MAX))
 
106
#else /* !__GNU__ */
 
107
#define OPEN_MAX NOFILES_MAX
 
108
#endif /* __GNU__ */
 
109
#else /* !__UNIXOS2__ && !__QNX__ */
 
110
#define OPEN_MAX 256
 
111
#endif /* __UNIXOS2__ */
 
112
#endif
 
113
#endif
 
114
#endif
 
115
#endif
 
116
#endif
 
117
 
 
118
#ifdef __GNU__
 
119
#define FS_OPEN_MAX 256
 
120
#else /*!__GNU__*/
 
121
#if OPEN_MAX > 256
 
122
#define FS_OPEN_MAX 256
 
123
#else
 
124
#define FS_OPEN_MAX OPEN_MAX
 
125
#endif
 
126
#endif /*__GNU__*/
 
127
 
 
128
#endif /* FS_OPEN_MAX */
 
129
 
 
130
/* Utek leaves kernel macros around in include files (bleah) */
 
131
 
 
132
#ifdef dirty
 
133
#undef dirty
 
134
#endif
 
135
 
 
136
#ifdef WORD64
 
137
#define NMSKBITS 64
 
138
#else
 
139
#define NMSKBITS 32
 
140
#endif
 
141
 
 
142
#define MSKCNT ((FS_OPEN_MAX + NMSKBITS - 1) / NMSKBITS)
 
143
 
 
144
#ifdef LONG64
 
145
typedef unsigned int FdSet[MSKCNT];
 
146
#else
 
147
typedef unsigned long FdSet[MSKCNT];
 
148
#endif
 
149
 
 
150
#if (MSKCNT==1)
 
151
#define BITMASK(i) (1 << (i))
 
152
#define MASKIDX(i) 0
 
153
#endif
 
154
 
 
155
#if (MSKCNT>1)
 
156
#define BITMASK(i) (1 << ((i) & (NMSKBITS - 1)))
 
157
#define MASKIDX(i) ((i) / NMSKBITS)
 
158
#endif
 
159
 
 
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))
 
164
 
 
165
#if (MSKCNT==1)
 
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])
 
172
#endif
 
173
 
 
174
#if (MSKCNT==2)
 
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) {\
 
184
                      dst[0] &= ~b1[0]; \
 
185
                      dst[1] &= ~b1[1]; }
 
186
#define _FSANYSET(src) (src[0] || src[1])
 
187
#endif
 
188
 
 
189
#if (MSKCNT==3)
 
190
#define COPYBITS(src, dst) { dst[0] = src[0]; dst[1] = src[1]; \
 
191
                             dst[2] = src[2]; }
 
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) {\
 
202
                      dst[0] &= ~b1[0]; \
 
203
                      dst[1] &= ~b1[1]; \
 
204
                      dst[2] &= ~b1[2]; }
 
205
#define _FSANYSET(src) (src[0] || src[1] || src[2])
 
206
#endif
 
207
 
 
208
#if (MSKCNT==4)
 
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) \
 
223
                      dst[0] &= ~b1[0]; \
 
224
                      dst[1] &= ~b1[1]; \
 
225
                      dst[2] &= ~b1[2]; \
 
226
                      dst[3] &= ~b1[3]
 
227
#define _FSANYSET(src) (src[0] || src[1] || src[2] || src[3])
 
228
#endif
 
229
 
 
230
#if (MSKCNT>4)
 
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)  \
 
234
                      { int cri;                        \
 
235
                        for (cri=0; cri<MSKCNT; cri++)  \
 
236
                          dst[cri] = (b1[cri] & b2[cri]) }
 
237
#define ORBITS(dst, b1, b2)  \
 
238
                      { int cri;                        \
 
239
                      for (cri=0; cri<MSKCNT; cri++)    \
 
240
                          dst[cri] = (b1[cri] | b2[cri]) }
 
241
#define UNSETBITS(dst, b1) \
 
242
                      { int cri;                        \
 
243
                      for (cri=0; cri<MSKCNT; cri++)    \
 
244
                          dst[cri] &= ~b1[cri];  }
 
245
#if (MSKCNT==8)
 
246
#define _FSANYSET(src) (src[0] || src[1] || src[2] || src[3] || \
 
247
                        src[4] || src[5] || src[6] || src[7])
 
248
#endif
 
249
/*
 
250
 * If MSKCNT>4 and not 8, then _FSANYSET is a routine defined in FSlibInt.c.
 
251
 *
 
252
 * #define _FSANYSET(src) (src[0] || src[1] || src[2] || src[3] || src[4] ...)
 
253
 */
 
254
#endif
 
255
 
 
256
 
 
257
#else
 
258
 
 
259
#include <X11/Xwinsock.h>
 
260
#include <X11/Xw32defs.h>
 
261
 
 
262
typedef fd_set FdSet;
 
263
 
 
264
#define CLEARBITS(set) FD_ZERO(&set)
 
265
#define BITSET(set,s) FD_SET(s,&set)
 
266
#define _FSANYSET(set) set.fd_count
 
267
 
 
268
#endif
 
269
 
 
270
#include <X11/Xtrans/Xtrans.h>
 
271
#include <stdlib.h>
 
272
#include <string.h>
 
273
 
 
274
/*
 
275
 * The following definitions can be used for locking requests in multi-threaded
 
276
 * address spaces.
 
277
 */
 
278
#define LockDisplay(dis)
 
279
#define LockMutex(mutex)
 
280
#define UnlockMutex(mutex)
 
281
#define UnlockDisplay(dis)
 
282
#define FSfree(ptr) free((ptr))
 
283
 
 
284
 
 
285
/*
 
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.
 
290
 */
 
291
 
 
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))
 
296
 
 
297
#else
 
298
 
 
299
#define FSmalloc(size) malloc((size))
 
300
#define FSrealloc(ptr, size) realloc((ptr), (size))
 
301
#define FScalloc(nelem, elsize) calloc((nelem), (elsize))
 
302
#endif
 
303
 
 
304
/*
 
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.
 
308
 *
 
309
 *      struct iovec {
 
310
 *              caddr_t iov_base;
 
311
 *              int iov_len;
 
312
 *      };
 
313
 */
 
314
 
 
315
#ifdef USG
 
316
 
 
317
#if defined(USG) && !defined(CRAY) && !defined(umips) && !defined(MOTOROLA)
 
318
#ifndef __TIMEVAL__
 
319
#define __TIMEVAL__
 
320
struct timeval {                /* BSD has in <sys/time.h> */
 
321
    long        tv_sec;
 
322
    long        tv_usec;
 
323
};
 
324
 
 
325
#endif                          /* __TIMEVAL__ */
 
326
 
 
327
#endif                          /* not CRAY or umips */
 
328
 
 
329
#endif                          /* USG */
 
330
 
 
331
 
 
332
#define SearchString(string, char) index((string), (char))