]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/bits.h
This commit was manufactured by cvs2svn to create tag
[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    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
11
12    This program is free software; you can redistribute it and/or
13    modify it under the terms of the GNU General Public License as
14    published by the Free Software Foundation; either version 2 of
15    the License, or (at your option) any later version.
16
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20    General Public License for more details.
21
22    You should have received a copy of the GNU General Public
23    License along with this program; if not, write to the Free
24    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25    MA 02111-1307, USA.
26
27  */
28
29 #ifndef __BITS_H_
30 #define __BITS_H_
31
32 /* number of bytes to hold n bits */
33 #define nbytes_for_bits(n) ((((n)-1)>>3)+1) 
34
35 /* test if bit is set */
36 #define bit_is_set(b, var) (((var)[(b)>>3] & (1<<((b)&0x7))) != 0)
37
38 /* set bit */
39 #define set_bit(b, var) ((var)[(b)>>3] |= (1<<((b)&0x7)))
40
41 /* clear bit */
42 #define clear_bit(b, var) ((var)[(b)>>3] &= ~(1<<((b)&0x7)))
43
44 /* clear all bits */
45 #define clear_all_bits(b, var) memset(var, 0, nbytes_for_bits(b))
46
47 /* set range of bits */
48 #define set_bits(f, l, var) { \
49    int i; \
50    for (i=f; i<=l; i++)  \
51       set_bit(i, var); \
52 }
53  
54 /* clear range of bits */
55 #define clear_bits(f, l, var) { \
56    int i; \
57    for (i=f; i<=l; i++)  \
58       clear_bit(i, var); \
59 }
60
61 #endif /* __BITS_H_ */