xref: /freebsd/share/man/man3/bitstring.3 (revision 14a4d6d01335dd233023834e05897377cb70d52a)
1afe61c15SRodney W. Grimes.\" Copyright (c) 1989, 1991, 1993
2afe61c15SRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
3afe61c15SRodney W. Grimes.\"
4afe61c15SRodney W. Grimes.\" This code is derived from software contributed to Berkeley by
5afe61c15SRodney W. Grimes.\" Paul Vixie.
6afe61c15SRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
7afe61c15SRodney W. Grimes.\" modification, are permitted provided that the following conditions
8afe61c15SRodney W. Grimes.\" are met:
9afe61c15SRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
10afe61c15SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
11afe61c15SRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
12afe61c15SRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
13afe61c15SRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
14dda5b397SEitan Adler.\" 3. Neither the name of the University nor the names of its contributors
15afe61c15SRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
16afe61c15SRodney W. Grimes.\"    without specific prior written permission.
17afe61c15SRodney W. Grimes.\"
18afe61c15SRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19afe61c15SRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20afe61c15SRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21afe61c15SRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22afe61c15SRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23afe61c15SRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24afe61c15SRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25afe61c15SRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26afe61c15SRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27afe61c15SRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28afe61c15SRodney W. Grimes.\" SUCH DAMAGE.
29afe61c15SRodney W. Grimes.\"
301b82e02fSAlan Somers.\" Copyright (c) 2014,2016 Spectra Logic Corporation
318907f744SAlan Somers.\" All rights reserved.
328907f744SAlan Somers.\"
338907f744SAlan Somers.\" Redistribution and use in source and binary forms, with or without
348907f744SAlan Somers.\" modification, are permitted provided that the following conditions
358907f744SAlan Somers.\" are met:
368907f744SAlan Somers.\" 1. Redistributions of source code must retain the above copyright
378907f744SAlan Somers.\"    notice, this list of conditions, and the following disclaimer,
388907f744SAlan Somers.\"    without modification.
398907f744SAlan Somers.\" 2. Redistributions in binary form must reproduce at minimum a disclaimer
408907f744SAlan Somers.\"    substantially similar to the "NO WARRANTY" disclaimer below
418907f744SAlan Somers.\"    ("Disclaimer") and any redistribution must be conditioned upon
428907f744SAlan Somers.\"    including a substantially similar Disclaimer requirement for further
438907f744SAlan Somers.\"    binary redistribution.
448907f744SAlan Somers.\"
458907f744SAlan Somers.\" NO WARRANTY
468907f744SAlan Somers.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
478907f744SAlan Somers.\" "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
488907f744SAlan Somers.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
498907f744SAlan Somers.\" A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
508907f744SAlan Somers.\" HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
518907f744SAlan Somers.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
528907f744SAlan Somers.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
538907f744SAlan Somers.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
548907f744SAlan Somers.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
558907f744SAlan Somers.\" IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
568907f744SAlan Somers.\" POSSIBILITY OF SUCH DAMAGES.
578907f744SAlan Somers.\"
58afe61c15SRodney W. Grimes.\"     @(#)bitstring.3	8.1 (Berkeley) 7/19/93
597f3dea24SPeter Wemm.\" $FreeBSD$
60afe61c15SRodney W. Grimes.\"
61*14a4d6d0SVladimir Kondratyev.Dd August 8, 2021
62afe61c15SRodney W. Grimes.Dt BITSTRING 3
633d45e180SRuslan Ermilov.Os
64afe61c15SRodney W. Grimes.Sh NAME
65afe61c15SRodney W. Grimes.Nm bit_alloc ,
66afe61c15SRodney W. Grimes.Nm bit_clear ,
671b82e02fSAlan Somers.Nm bit_count ,
68afe61c15SRodney W. Grimes.Nm bit_decl ,
698907f744SAlan Somers.Nm bit_ffc ,
70afe61c15SRodney W. Grimes.Nm bit_ffs ,
718907f744SAlan Somers.Nm bit_ffc_at ,
728907f744SAlan Somers.Nm bit_ffs_at ,
7352e8f6a3SEric Joyner.Nm bit_ffc_area ,
7452e8f6a3SEric Joyner.Nm bit_ffs_area ,
7552e8f6a3SEric Joyner.Nm bit_ffc_area_at ,
7652e8f6a3SEric Joyner.Nm bit_ffs_area_at ,
77afe61c15SRodney W. Grimes.Nm bit_nclear ,
78afe61c15SRodney W. Grimes.Nm bit_nset ,
79afe61c15SRodney W. Grimes.Nm bit_set ,
808907f744SAlan Somers.Nm bit_test ,
818907f744SAlan Somers.Nm bitstr_size
828907f744SAlan Somers.Nd bit-string manipulation functions and macros
83afe61c15SRodney W. Grimes.Sh SYNOPSIS
8432eef9aeSRuslan Ermilov.In bitstring.h
85afe61c15SRodney W. Grimes.Ft bitstr_t *
86afe61c15SRodney W. Grimes.Fn bit_alloc "int nbits"
8769a6a1d7SBruce Evans.Ft void
8869a6a1d7SBruce Evans.Fn bit_decl "bitstr_t *name" "int nbits"
8969a6a1d7SBruce Evans.Ft void
9069a6a1d7SBruce Evans.Fn bit_clear "bitstr_t *name" "int bit"
9169a6a1d7SBruce Evans.Ft void
921b82e02fSAlan Somers.Fn bit_count "bitstr_t *name" "int count" "int nbits" "int *value"
931b82e02fSAlan Somers.Ft void
9469a6a1d7SBruce Evans.Fn bit_ffc "bitstr_t *name" "int nbits" "int *value"
9569a6a1d7SBruce Evans.Ft void
9669a6a1d7SBruce Evans.Fn bit_ffs "bitstr_t *name" "int nbits" "int *value"
9769a6a1d7SBruce Evans.Ft void
988907f744SAlan Somers.Fn bit_ffc_at "bitstr_t *name" "int start" "int nbits" "int *value"
998907f744SAlan Somers.Ft void
1008907f744SAlan Somers.Fn bit_ffs_at "bitstr_t *name" "int start" "int nbits" "int *value"
1018907f744SAlan Somers.Ft void
10252e8f6a3SEric Joyner.Fn bit_ffc_area "bitstr_t *name" "int nbits" "int size" "int *value"
10352e8f6a3SEric Joyner.Ft void
10452e8f6a3SEric Joyner.Fn bit_ffs_area "bitstr_t *name" "int nbits" "int size" "int *value"
10552e8f6a3SEric Joyner.Ft void
10652e8f6a3SEric Joyner.Fn bit_ffc_area_at "bitstr_t *name" "int start" "int nbits" "int size" "int *value"
10752e8f6a3SEric Joyner.Ft void
10852e8f6a3SEric Joyner.Fn bit_ffs_area_at "bitstr_t *name" "int start" "int nbits" "int size" "int *value"
109*14a4d6d0SVladimir Kondratyev.Fn bit_foreach "bitstr_t *name" "int nbits" "int var"
110*14a4d6d0SVladimir Kondratyev.Fn bit_foreach_at "bitstr_t *name" "int start" "int nbits" "int var"
111*14a4d6d0SVladimir Kondratyev.Fn bit_foreach_unset "bitstr_t *name" "int nbits" "int var"
112*14a4d6d0SVladimir Kondratyev.Fn bit_foreach_unset_at "bitstr_t *name" "int start" "int nbits" "int var"
11352e8f6a3SEric Joyner.Ft void
11469a6a1d7SBruce Evans.Fn bit_nclear "bitstr_t *name" "int start" "int stop"
11569a6a1d7SBruce Evans.Ft void
11669a6a1d7SBruce Evans.Fn bit_nset "bitstr_t *name" "int start" "int stop"
11769a6a1d7SBruce Evans.Ft void
11869a6a1d7SBruce Evans.Fn bit_set "bitstr_t *name" "int bit"
11969a6a1d7SBruce Evans.Ft int
120afe61c15SRodney W. Grimes.Fn bitstr_size "int nbits"
12169a6a1d7SBruce Evans.Ft int
12269a6a1d7SBruce Evans.Fn bit_test "bitstr_t *name" "int bit"
123afe61c15SRodney W. Grimes.Sh DESCRIPTION
124afe61c15SRodney W. GrimesThese macros operate on strings of bits.
125afe61c15SRodney W. Grimes.Pp
1268907f744SAlan SomersThe function
127afe61c15SRodney W. Grimes.Fn bit_alloc
128afe61c15SRodney W. Grimesreturns a pointer of type
129afe61c15SRodney W. Grimes.Dq Fa "bitstr_t *"
130afe61c15SRodney W. Grimesto sufficient space to store
131afe61c15SRodney W. Grimes.Fa nbits
132afe61c15SRodney W. Grimesbits, or
133afe61c15SRodney W. Grimes.Dv NULL
134afe61c15SRodney W. Grimesif no space is available.
1358907f744SAlan SomersIf successful, the returned bit string is initialized with all bits cleared.
136afe61c15SRodney W. Grimes.Pp
137afe61c15SRodney W. GrimesThe macro
138afe61c15SRodney W. Grimes.Fn bit_decl
1398907f744SAlan Somersdeclares a bit string with sufficient space to store
140afe61c15SRodney W. Grimes.Fa nbits
1418907f744SAlan Somersbits.
1428907f744SAlan Somers.Fn bit_decl
1438907f744SAlan Somersmay be used to include statically sized bit strings in structure
1448907f744SAlan Somersdefinitions or to create bit strings on the stack.
1458907f744SAlan SomersUsers of this macro are responsible for initialization of the bit string,
1468907f744SAlan Somerstypically via a global initialization of the containing struct or use of the
1478907f744SAlan Somers.Fn bit_nset
1488907f744SAlan Somersor
1498907f744SAlan Somers.Fn bin_nclear
1508907f744SAlan Somersfunctions.
151afe61c15SRodney W. Grimes.Pp
152afe61c15SRodney W. GrimesThe macro
153afe61c15SRodney W. Grimes.Fn bitstr_size
1548907f744SAlan Somersreturns the number of bytes necessary to store
155afe61c15SRodney W. Grimes.Fa nbits
156afe61c15SRodney W. Grimesbits.
157afe61c15SRodney W. GrimesThis is useful for copying bit strings.
158afe61c15SRodney W. Grimes.Pp
1598907f744SAlan SomersThe functions
160afe61c15SRodney W. Grimes.Fn bit_clear
161afe61c15SRodney W. Grimesand
162afe61c15SRodney W. Grimes.Fn bit_set
163afe61c15SRodney W. Grimesclear or set the zero-based numbered bit
164afe61c15SRodney W. Grimes.Fa bit ,
165afe61c15SRodney W. Grimesin the bit string
166afe61c15SRodney W. Grimes.Ar name .
167afe61c15SRodney W. Grimes.Pp
168afe61c15SRodney W. GrimesThe
169afe61c15SRodney W. Grimes.Fn bit_nset
170afe61c15SRodney W. Grimesand
171afe61c15SRodney W. Grimes.Fn bit_nclear
1728907f744SAlan Somersfunctions
173afe61c15SRodney W. Grimesset or clear the zero-based numbered bits from
174afe61c15SRodney W. Grimes.Fa start
1750b607240SJohn-Mark Gurneythrough
176afe61c15SRodney W. Grimes.Fa stop
177afe61c15SRodney W. Grimesin the bit string
178afe61c15SRodney W. Grimes.Ar name .
179afe61c15SRodney W. Grimes.Pp
180afe61c15SRodney W. GrimesThe
181afe61c15SRodney W. Grimes.Fn bit_test
1828907f744SAlan Somersfunction
183afe61c15SRodney W. Grimesevaluates to non-zero if the zero-based numbered bit
184afe61c15SRodney W. Grimes.Fa bit
185afe61c15SRodney W. Grimesof bit string
186afe61c15SRodney W. Grimes.Fa name
187afe61c15SRodney W. Grimesis set, and zero otherwise.
188afe61c15SRodney W. Grimes.Pp
1898907f744SAlan SomersThe function
190afe61c15SRodney W. Grimes.Fn bit_ffc
191afe61c15SRodney W. Grimesstores in the location referenced by
192afe61c15SRodney W. Grimes.Fa value
193afe61c15SRodney W. Grimesthe zero-based number of the first bit not set in the array of
194afe61c15SRodney W. Grimes.Fa nbits
195afe61c15SRodney W. Grimesbits referenced by
196afe61c15SRodney W. Grimes.Fa name .
197afe61c15SRodney W. GrimesIf all bits are set, the location referenced by
198afe61c15SRodney W. Grimes.Fa value
199afe61c15SRodney W. Grimesis set to \-1.
200afe61c15SRodney W. Grimes.Pp
2018907f744SAlan SomersThe
2028907f744SAlan Somers.Fn bit_ffs
2038907f744SAlan Somersfunction
2048907f744SAlan Somersstores in the location referenced by
2058907f744SAlan Somers.Fa value
2068907f744SAlan Somersthe zero-based number of the first bit set in the array of
2078907f744SAlan Somers.Fa nbits
2088907f744SAlan Somersbits referenced by
2098907f744SAlan Somers.Fa name .
2108907f744SAlan SomersIf no bits are set, the location referenced by
2118907f744SAlan Somers.Fa value
2128907f744SAlan Somersis set to \-1.
2138907f744SAlan Somers.Pp
2148907f744SAlan SomersThe function
2158907f744SAlan Somers.Fn bit_ffc_at
2168907f744SAlan Somersstores in the location referenced by
2178907f744SAlan Somers.Fa value
2188907f744SAlan Somersthe zero-based number of the first bit not set in the array of
2198907f744SAlan Somers.Fa nbits
2208907f744SAlan Somersbits referenced by
2218907f744SAlan Somers.Fa name ,
2228907f744SAlan Somersat or after the zero-based bit index
2238907f744SAlan Somers.Fa start .
2248907f744SAlan SomersIf all bits at or after
2258907f744SAlan Somers.Fa start
2268907f744SAlan Somersare set, the location referenced by
2278907f744SAlan Somers.Fa value
2288907f744SAlan Somersis set to \-1.
2298907f744SAlan Somers.Pp
2308907f744SAlan SomersThe
2318907f744SAlan Somers.Fn bit_ffs_at
2328907f744SAlan Somersfunction
2338907f744SAlan Somersstores in the location referenced by
2348907f744SAlan Somers.Fa value
2358907f744SAlan Somersthe zero-based number of the first bit set in the array of
2368907f744SAlan Somers.Fa nbits
2378907f744SAlan Somersbits referenced by
2388907f744SAlan Somers.Fa name ,
2398907f744SAlan Somersat or after the zero-based bit index
2408907f744SAlan Somers.Fa start .
2418907f744SAlan SomersIf no bits are set after
2428907f744SAlan Somers.Fa start ,
2438907f744SAlan Somersthe location referenced by
2448907f744SAlan Somers.Fa value
2458907f744SAlan Somersis set to \-1.
2468907f744SAlan Somers.Pp
2471b82e02fSAlan SomersThe
24852e8f6a3SEric Joyner.Fn bit_ffc_area
24952e8f6a3SEric Joynerfunction stores in the location referenced by
25052e8f6a3SEric Joyner.Fa value
25152e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of unset bits of
25252e8f6a3SEric Joynerat least
25352e8f6a3SEric Joyner.Fa size
25452e8f6a3SEric Joynerunset bits in the array of
25552e8f6a3SEric Joyner.Fa nbits
25652e8f6a3SEric Joynerbits referenced by
25752e8f6a3SEric Joyner.Fa name .
25852e8f6a3SEric JoynerIf no sequence of contiguous unset bits of the specified
25952e8f6a3SEric Joyner.Fa size
26052e8f6a3SEric Joynercan be found, the location referenced by
26152e8f6a3SEric Joyner.Fa value
26252e8f6a3SEric Joyneris set to \-1.
26352e8f6a3SEric Joyner.Pp
26452e8f6a3SEric JoynerThe
26552e8f6a3SEric Joyner.Fn bit_ffs_area
26652e8f6a3SEric Joynerfunction stores in the location referenced by
26752e8f6a3SEric Joyner.Fa value
26852e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of set bits of
26952e8f6a3SEric Joynerat least
27052e8f6a3SEric Joyner.Fa size
27152e8f6a3SEric Joynerset bits in the array of
27252e8f6a3SEric Joyner.Fa nbits
27352e8f6a3SEric Joynerbits referenced by
27452e8f6a3SEric Joyner.Fa name .
27552e8f6a3SEric JoynerIf no sequence of contiguous set bits of the specified
27652e8f6a3SEric Joyner.Fa size
27752e8f6a3SEric Joynercan be found, the location referenced by
27852e8f6a3SEric Joyner.Fa value
27952e8f6a3SEric Joyneris set to \-1.
28052e8f6a3SEric Joyner.Pp
28152e8f6a3SEric JoynerThe
28252e8f6a3SEric Joyner.Fn bit_ffc_area_at
28352e8f6a3SEric Joynerfunction stores in the location referenced by
28452e8f6a3SEric Joyner.Fa value
28552e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of unset bits of
28652e8f6a3SEric Joynerat least
28752e8f6a3SEric Joyner.Fa size
28852e8f6a3SEric Joynerunset bits in the array of
28952e8f6a3SEric Joyner.Fa nbits
29052e8f6a3SEric Joynerbits referenced by
29152e8f6a3SEric Joyner.Fa name ,
29252e8f6a3SEric Joynerat or after the zero-based bit index
29352e8f6a3SEric Joyner.Fa start .
29452e8f6a3SEric JoynerIf no sequence of contiguous unset bits of the specified
29552e8f6a3SEric Joyner.Fa size
29652e8f6a3SEric Joynercan be found at or after
29752e8f6a3SEric Joyner.Fa start ,
29852e8f6a3SEric Joynerthe location referenced by
29952e8f6a3SEric Joyner.Fa value
30052e8f6a3SEric Joyneris set to \-1.
30152e8f6a3SEric Joyner.Pp
30252e8f6a3SEric JoynerThe
30352e8f6a3SEric Joyner.Fn bit_ffs_area_at
30452e8f6a3SEric Joynerfunction stores in the location referenced by
30552e8f6a3SEric Joyner.Fa value
30652e8f6a3SEric Joynerthe zero-based number of the first bit beginning a sequence of set bits of
30752e8f6a3SEric Joynerat least
30852e8f6a3SEric Joyner.Fa size
30952e8f6a3SEric Joynerset bits in the array of
31052e8f6a3SEric Joyner.Fa nbits
31152e8f6a3SEric Joynerbits referenced by
31252e8f6a3SEric Joyner.Fa name ,
31352e8f6a3SEric Joynerat or after the zero-based bit index
31452e8f6a3SEric Joyner.Fa start .
31552e8f6a3SEric JoynerIf no sequence of contiguous set bits of the specified
31652e8f6a3SEric Joyner.Fa size
31752e8f6a3SEric Joynercan be found at or after
31852e8f6a3SEric Joyner.Fa start ,
31952e8f6a3SEric Joynerthe location referenced by
32052e8f6a3SEric Joyner.Fa value
32152e8f6a3SEric Joyneris set to \-1.
32252e8f6a3SEric Joyner.Pp
32352e8f6a3SEric JoynerThe
3241b82e02fSAlan Somers.Fn bit_count
3251b82e02fSAlan Somersfunction stores in the location referenced by
3261b82e02fSAlan Somers.Fa value
3271b82e02fSAlan Somersthe number of bits set in the array of
3281b82e02fSAlan Somers.Fa nbits
3291b82e02fSAlan Somersbits referenced by
3301b82e02fSAlan Somers.Fa name ,
3311b82e02fSAlan Somersat or after the zero-based bit index
3321b82e02fSAlan Somers.Fa start .
3331b82e02fSAlan Somers.Pp
334*14a4d6d0SVladimir KondratyevThe macro
335*14a4d6d0SVladimir Kondratyev.Fn bit_foreach
336*14a4d6d0SVladimir Kondratyevtraverses all set bits in the array of
337*14a4d6d0SVladimir Kondratyev.Fa nbits
338*14a4d6d0SVladimir Kondratyevreferenced by
339*14a4d6d0SVladimir Kondratyev.Fa name
340*14a4d6d0SVladimir Kondratyevin the forward direction, assigning each location in turn to
341*14a4d6d0SVladimir Kondratyev.Fa var .
342*14a4d6d0SVladimir Kondratyev.Pp
343*14a4d6d0SVladimir KondratyevThe macro
344*14a4d6d0SVladimir Kondratyev.Fn bit_foreach_at
345*14a4d6d0SVladimir Kondratyevtraverses all set bits in the array of
346*14a4d6d0SVladimir Kondratyev.Fa nbits
347*14a4d6d0SVladimir Kondratyevreferenced by
348*14a4d6d0SVladimir Kondratyev.Fa name
349*14a4d6d0SVladimir Kondratyevin the forward direction at or after the zero-based bit index
350*14a4d6d0SVladimir Kondratyev.Fa start ,
351*14a4d6d0SVladimir Kondratyevassigning each location in turn to
352*14a4d6d0SVladimir Kondratyev.Fa var .
353*14a4d6d0SVladimir Kondratyev.Pp
354*14a4d6d0SVladimir KondratyevThe macro
355*14a4d6d0SVladimir Kondratyev.Fn bit_foreach_unset
356*14a4d6d0SVladimir Kondratyevtraverses all unset bits in the array of
357*14a4d6d0SVladimir Kondratyev.Fa nbits
358*14a4d6d0SVladimir Kondratyevreferenced by
359*14a4d6d0SVladimir Kondratyev.Fa name
360*14a4d6d0SVladimir Kondratyevin the forward direction, assigning each location in turn to
361*14a4d6d0SVladimir Kondratyev.Fa var .
362*14a4d6d0SVladimir Kondratyev.Pp
363*14a4d6d0SVladimir KondratyevThe macro
364*14a4d6d0SVladimir Kondratyev.Fn bit_foreach_unset_at
365*14a4d6d0SVladimir Kondratyevtraverses all unset bits in the array of
366*14a4d6d0SVladimir Kondratyev.Fa nbits
367*14a4d6d0SVladimir Kondratyevreferenced by
368*14a4d6d0SVladimir Kondratyev.Fa name
369*14a4d6d0SVladimir Kondratyevin the forward direction at or after the zero-based bit index
370*14a4d6d0SVladimir Kondratyev.Fa start ,
371*14a4d6d0SVladimir Kondratyevassigning each location in turn to
372*14a4d6d0SVladimir Kondratyev.Fa var .
373*14a4d6d0SVladimir Kondratyev.Pp
3748907f744SAlan SomersThe arguments in bit string macros are evaluated only once and may safely
375afe61c15SRodney W. Grimeshave side effects.
376251c176fSRuslan Ermilov.Sh EXAMPLES
377afe61c15SRodney W. Grimes.Bd -literal -offset indent
378afe61c15SRodney W. Grimes#include <limits.h>
379afe61c15SRodney W. Grimes#include <bitstring.h>
380afe61c15SRodney W. Grimes
3813136363fSRuslan Ermilov\&...
382afe61c15SRodney W. Grimes#define	LPR_BUSY_BIT		0
383afe61c15SRodney W. Grimes#define	LPR_FORMAT_BIT		1
384afe61c15SRodney W. Grimes#define	LPR_DOWNLOAD_BIT	2
3853136363fSRuslan Ermilov\&...
386afe61c15SRodney W. Grimes#define	LPR_AVAILABLE_BIT	9
387afe61c15SRodney W. Grimes#define	LPR_MAX_BITS		10
388afe61c15SRodney W. Grimes
389afe61c15SRodney W. Grimesmake_lpr_available()
390afe61c15SRodney W. Grimes{
391afe61c15SRodney W. Grimes	bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
392afe61c15SRodney W. Grimes	...
393afe61c15SRodney W. Grimes	bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
394afe61c15SRodney W. Grimes	...
395afe61c15SRodney W. Grimes	if (!bit_test(bitlist, LPR_BUSY_BIT)) {
396afe61c15SRodney W. Grimes		bit_clear(bitlist, LPR_FORMAT_BIT);
397afe61c15SRodney W. Grimes		bit_clear(bitlist, LPR_DOWNLOAD_BIT);
398afe61c15SRodney W. Grimes		bit_set(bitlist, LPR_AVAILABLE_BIT);
399afe61c15SRodney W. Grimes	}
400afe61c15SRodney W. Grimes}
401afe61c15SRodney W. Grimes.Ed
402afe61c15SRodney W. Grimes.Sh SEE ALSO
4037ebf4122SConrad Meyer.Xr malloc 3 ,
4047ebf4122SConrad Meyer.Xr bitset 9
405afe61c15SRodney W. Grimes.Sh HISTORY
406afe61c15SRodney W. GrimesThe
407afe61c15SRodney W. Grimes.Nm bitstring
40821421932SMike Pritchardfunctions first appeared in
40921421932SMike Pritchard.Bx 4.4 .
410