1bitstring(3bsd) LOCAL bitstring(3bsd)
2
4 bit_alloc, bit_clear, bit_decl, bit_ffs, bit_nclear, bit_nset, bit_set,
5 bitstr_size, bit_test — bit-string manipulation macros
6
8 Utility functions from BSD systems (libbsd, -lbsd)
9
11 #include <bitstring.h>
12 (See libbsd(7) for include usage.)
13
14 bitstr_t *
15 bit_alloc(int nbits);
16
17 void
18 bit_decl(bitstr_t *name, int nbits);
19
20 void
21 bit_clear(bitstr_t *name, int bit);
22
23 void
24 bit_ffc(bitstr_t *name, int nbits, int *value);
25
26 void
27 bit_ffs(bitstr_t *name, int nbits, int *value);
28
29 void
30 bit_nclear(bitstr_t *name, int start, int stop);
31
32 void
33 bit_nset(bitstr_t *name, int start, int stop);
34
35 void
36 bit_set(bitstr_t *name, int bit);
37
38 int
39 bitstr_size(int nbits);
40
41 int
42 bit_test(bitstr_t *name, int bit);
43
45 These macros operate on strings of bits.
46
47 The macro bit_alloc() returns a pointer of type “bitstr_t *” to suffi‐
48 cient space to store nbits bits, or NULL if no space is available.
49
50 The macro bit_decl() allocates sufficient space to store nbits bits on
51 the stack.
52
53 The macro bitstr_size() returns the number of elements of type bitstr_t
54 necessary to store nbits bits. This is useful for copying bit strings.
55
56 The macros bit_clear() and bit_set() clear or set the zero-based numbered
57 bit bit, in the bit string name.
58
59 The bit_nset() and bit_nclear() macros set or clear the zero-based num‐
60 bered bits from start through stop in the bit string name.
61
62 The bit_test() macro evaluates to non-zero if the zero-based numbered bit
63 bit of bit string name is set, and zero otherwise.
64
65 The bit_ffs() macro stores in the location referenced by value the zero-
66 based number of the first bit set in the array of nbits bits referenced
67 by name. If no bits are set, the location referenced by value is set to
68 -1.
69
70 The macro bit_ffc() stores in the location referenced by value the zero-
71 based number of the first bit not set in the array of nbits bits refer‐
72 enced by name. If all bits are set, the location referenced by value is
73 set to -1.
74
75 The arguments to these macros are evaluated only once and may safely have
76 side effects.
77
79 #include <limits.h>
80 #include <bsd/bitstring.h>
81
82 ...
83 #define LPR_BUSY_BIT 0
84 #define LPR_FORMAT_BIT 1
85 #define LPR_DOWNLOAD_BIT 2
86 ...
87 #define LPR_AVAILABLE_BIT 9
88 #define LPR_MAX_BITS 10
89
90 make_lpr_available()
91 {
92 bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
93 ...
94 bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
95 ...
96 if (!bit_test(bitlist, LPR_BUSY_BIT)) {
97 bit_clear(bitlist, LPR_FORMAT_BIT);
98 bit_clear(bitlist, LPR_DOWNLOAD_BIT);
99 bit_set(bitlist, LPR_AVAILABLE_BIT);
100 }
101 }
102
104 malloc(3)
105
107 The bitstring functions first appeared in 4.4BSD.
108
109BSD July 19, 1993 BSD