]> git.pond.sub.org Git - empserver/blob - include/bit.h
Indented with src/scripts/indent-emp.
[empserver] / include / bit.h
1 /*
2  *  Empire - A multi-player, client/server Internet based war game.
3  *  Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
4  *                           Ken Stevens, Steve McClure
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  *  ---
21  *
22  *  See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
23  *  related information and legal notices. It is expected that any future
24  *  projects/authors will amend these files as needed.
25  *
26  *  ---
27  *
28  *  bit.h: Definitions for variable sized bitfields
29  * 
30  *  Known contributors to this file:
31  *  
32  */
33
34 #ifndef _BIT_H_
35 #define _BIT_H_
36
37 typedef unsigned int bit_mask;
38 typedef bit_mask *bit_fdmask;
39
40 #ifndef bit
41 #define bit(x)          (1 << (x))
42 #endif
43
44 /*
45  * File descriptor bit manipulation macros for use with select(2)
46  */
47 #define BIT_NBBY        8
48 #define BIT_BITSPERMASK (sizeof(bit_mask) * BIT_NBBY)
49
50 #define BIT_SETB(a,b)   \
51         ((b)[(a)/BIT_BITSPERMASK] |= 1 << ((a) % BIT_BITSPERMASK))
52 #define BIT_CLRB(a,b)   \
53         ((b)[(a)/BIT_BITSPERMASK] &= ~(1<< ((a) % BIT_BITSPERMASK)))
54 #define BIT_ISSETB(a,b) \
55         ((b)[(a)/BIT_BITSPERMASK] & (1<< ((a) % BIT_BITSPERMASK)))
56 #define BIT_ISCLRB(a,b) \
57         (((b)[(a)/BIT_BITSPERMASK] & (1<<((a) % BIT_BITSPERMASK))) == 0)
58
59 extern bit_fdmask bit_newfdmask();
60
61 extern bit_fdmask bit_newfdmask(void);
62 extern void bit_zero(bit_fdmask);
63 extern void bit_not(bit_fdmask);
64 extern void bit_copy(bit_fdmask, bit_fdmask);
65 extern void bit_or(bit_fdmask, bit_fdmask);
66 extern void bit_or3(bit_fdmask, bit_fdmask, bit_fdmask);
67 extern void bit_and(bit_fdmask, bit_fdmask);
68 extern void bit_and3(bit_fdmask, bit_fdmask, bit_fdmask);
69 extern int bit_fd(bit_fdmask);
70
71 #endif /* _BIT_H_ */