]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/bits.h
Change copyright as per agreement with FSFE
[bacula/bacula] / bacula / src / lib / bits.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2016 Kern Sibbald
5
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13
14    This notice must be preserved when any source code is 
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /* Some elementary bit manipulations
20  *
21  *   Kern Sibbald, MM
22  *
23  *  NOTE:  base 0
24  *
25  */
26
27 #ifndef __BITS_H_
28 #define __BITS_H_
29
30 /* number of bytes to hold n bits */
31 #define nbytes_for_bits(n) ((((n)-1)>>3)+1)
32
33 /* test if bit is set */
34 #define bit_is_set(b, var) (((var)[(b)>>3] & (1<<((b)&0x7))) != 0)
35
36 /* set bit */
37 #define set_bit(b, var) ((var)[(b)>>3] |= (1<<((b)&0x7)))
38
39 /* clear bit */
40 #define clear_bit(b, var) ((var)[(b)>>3] &= ~(1<<((b)&0x7)))
41
42 /* clear all bits */
43 #define clear_all_bits(b, var) memset(var, 0, nbytes_for_bits(b))
44
45 /* set range of bits */
46 #define set_bits(f, l, var) { \
47    int i; \
48    for (i=f; i<=l; i++)  \
49       set_bit(i, var); \
50 }
51
52 /* clear range of bits */
53 #define clear_bits(f, l, var) { \
54    int i; \
55    for (i=f; i<=l; i++)  \
56       clear_bit(i, var); \
57 }
58
59 #endif /* __BITS_H_ */