blob: fa8ade948a612029d5408e586ba4a4258a171e61 [file] [log] [blame]
Guido van Rossumed233a51992-06-23 09:07:03 +00001/***********************************************************
2Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
3Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
25/* Common definitions for files that use the BSD select system call.
26 This is so complicated because every UNIX variant requires that
27 you include a different set of headers. Customizing this one file
28 should be easier than patching each of the files using select()... */
29
30
31/* XXX You may have to include some of these only if not already included */
32#include <sys/types.h>
33#include <sys/time.h> /* Implies <time.h> everywhere, as far as I know */
34#include <sys/param.h>
35
36
37/* Hacks for various systems that need hand-holding... */
38
39#ifdef _SEQUENT_
40#include <sys/select.h>
41/* Sequent doesn't seem to define struct timezone anywhere?!?! */
42struct timezone {
43 int tz_minuteswest;
44 int tz_dsttime;
45};
46#endif
47
48#ifdef _AIX /* I *think* this works */
49/* AIX defines fd_set in a separate file. Sigh... */
50#include <sys/select.h>
51#endif
52
53
54
55/* (Very) old versions of BSD don't define the FD_* set of macros.
56 The following will usually do... */
57
58#ifndef FD_SETSIZE
59#define FD_SETSIZE 256
60#endif
61
62#ifndef FD_SET
63
64typedef long fd_mask;
65
66#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
67#ifndef howmany
68#define howmany(x, y) (((x)+((y)-1))/(y))
69#endif
70
71typedef struct fd_set {
72 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
73} fd_set;
74
75#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
76#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
77#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
78#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
79
80#endif /* FD_SET */