]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/bits.h
kes Change Bacula trademark owner from John Walker to Kern Sibbald
[bacula/bacula] / bacula / src / lib / bits.h
1 /* Some elementary bit manipulations
2  *
3  *   Kern Sibbald, MM
4  *
5  *  NOTE:  base 0
6  *
7  *   Version $Id$
8  */
9 /*
10    Bacula® - The Network Backup Solution
11
12    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
13
14    The main author of Bacula is Kern Sibbald, with contributions from
15    many others, a complete list can be found in the file AUTHORS.
16    This program is Free Software; you can redistribute it and/or
17    modify it under the terms of version two of the GNU General Public
18    License as published by the Free Software Foundation and included
19    in the file LICENSE.
20
21    This program is distributed in the hope that it will be useful, but
22    WITHOUT ANY WARRANTY; without even the implied warranty of
23    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24    General Public License for more details.
25
26    You should have received a copy of the GNU General Public License
27    along with this program; if not, write to the Free Software
28    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29    02110-1301, USA.
30
31    Bacula® is a registered trademark of Kern Sibbald.
32    The licensor of Bacula is the Free Software Foundation Europe
33    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
34    Switzerland, email:ftf@fsfeurope.org.
35 */
36
37 #ifndef __BITS_H_
38 #define __BITS_H_
39
40 /* number of bytes to hold n bits */
41 #define nbytes_for_bits(n) ((((n)-1)>>3)+1)
42
43 /* test if bit is set */
44 #define bit_is_set(b, var) (((var)[(b)>>3] & (1<<((b)&0x7))) != 0)
45
46 /* set bit */
47 #define set_bit(b, var) ((var)[(b)>>3] |= (1<<((b)&0x7)))
48
49 /* clear bit */
50 #define clear_bit(b, var) ((var)[(b)>>3] &= ~(1<<((b)&0x7)))
51
52 /* clear all bits */
53 #define clear_all_bits(b, var) memset(var, 0, nbytes_for_bits(b))
54
55 /* set range of bits */
56 #define set_bits(f, l, var) { \
57    int i; \
58    for (i=f; i<=l; i++)  \
59       set_bit(i, var); \
60 }
61
62 /* clear range of bits */
63 #define clear_bits(f, l, var) { \
64    int i; \
65    for (i=f; i<=l; i++)  \
66       clear_bit(i, var); \
67 }
68
69 #endif /* __BITS_H_ */