Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The |
| 3 | Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF 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?!?! */ |
| 42 | struct 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 | |
| 64 | typedef 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 | |
| 71 | typedef 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))) |
Guido van Rossum | 4fbf798 | 1992-08-04 09:13:45 +0000 | [diff] [blame] | 78 | #define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p))) |
Guido van Rossum | ed233a5 | 1992-06-23 09:07:03 +0000 | [diff] [blame] | 79 | |
| 80 | #endif /* FD_SET */ |