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
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.
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.
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
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.
28 * bit.c: Bit field manipulation routines
30 * Known contributors to this file:
39 * allocate and search select-style bitfields
49 void bit_zero(bit_fdmask);
54 extern s_char *malloc();
58 bit_nfile = getfdtablesize();
59 bit_nbytes = (bit_nfile + (BIT_BITSPERMASK-1)) / BIT_NBBY;
61 mask = (bit_fdmask) malloc(bit_nbytes);
62 (void) bit_zero(mask);
78 nwords = bit_nbytes / sizeof(*mask);
79 for (i=0; i<nwords; i++)
90 register bit_mask *mask;
95 nwords = bit_nbytes / sizeof(*mask);
96 for (i=0; i<nwords; i++,mask++)
104 bit_copy(bitsrc, bitdst)
108 register bit_mask *src;
109 register bit_mask *dst;
115 nwords = bit_nbytes / sizeof(*dst);
116 for (i=0; i<nwords; i++)
124 bit_or(bitsrc, bitdst)
128 register bit_mask *src;
129 register bit_mask *dst;
133 nwords = bit_nbytes / sizeof(*dst);
136 for (i=0; i<nwords; i++)
144 bit_or3(bitsrc1, bitsrc2, bitdst)
149 register bit_mask *src1;
150 register bit_mask *src2;
151 register bit_mask *dst;
158 nwords = bit_nbytes / sizeof(*dst);
159 for (i=0; i<nwords; i++)
160 *dst++ = *src1++ | *src2++;
167 bit_and(bitsrc, bitdst)
171 register bit_mask *src;
172 register bit_mask *dst;
176 nwords = bit_nbytes / sizeof(*src);
179 for (i=0; i<nwords; i++)
187 bit_and3(bitsrc1, bitsrc2, bitdst)
192 register bit_mask *src1;
193 register bit_mask *src2;
194 register bit_mask *dst;
201 nwords = bit_nbytes / sizeof(*dst);
202 for (i=0; i<nwords; i++)
203 *dst++ = *src1++ & *src2++;
207 * Return first bit set in fd mask.
208 * speedy version, not using BIT_ISSETB()
214 register bit_mask *mask;
215 register unsigned int j;
221 nwords = bit_nbytes / sizeof(m);
222 for (i=0; i<nwords; i++,mask++) {
223 if ((m = *mask) == 0)
225 for (j=0; j<BIT_BITSPERMASK; j++) {
227 return i*BIT_BITSPERMASK + j;