xref: /netbsd-src/share/man/man9/setbit.9 (revision 7bb35895510fee918b3c2b016f0ce1cd664675ea)
1*7bb35895Schristos.\" $NetBSD: setbit.9,v 1.3 2012/12/04 18:03:37 christos Exp $
28e87fd3eSjruoho.\"
38e87fd3eSjruoho.\" Copyright (c) 2010 The NetBSD Foundation, Inc.
48e87fd3eSjruoho.\" All rights reserved.
58e87fd3eSjruoho.\"
68e87fd3eSjruoho.\" This code is derived from software contributed to The NetBSD Foundation
78e87fd3eSjruoho.\" by Jukka Ruohonen.
88e87fd3eSjruoho.\"
98e87fd3eSjruoho.\" Redistribution and use in source and binary forms, with or without
108e87fd3eSjruoho.\" modification, are permitted provided that the following conditions
118e87fd3eSjruoho.\" are met:
128e87fd3eSjruoho.\" 1. Redistributions of source code must retain the above copyright
138e87fd3eSjruoho.\"    notice, this list of conditions and the following disclaimer.
148e87fd3eSjruoho.\" 2. Redistributions in binary form must reproduce the above copyright
158e87fd3eSjruoho.\"    notice, this list of conditions and the following disclaimer in the
168e87fd3eSjruoho.\"    documentation and/or other materials provided with the distribution.
178e87fd3eSjruoho.\"
188e87fd3eSjruoho.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
198e87fd3eSjruoho.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
208e87fd3eSjruoho.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
218e87fd3eSjruoho.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
228e87fd3eSjruoho.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
238e87fd3eSjruoho.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
248e87fd3eSjruoho.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
258e87fd3eSjruoho.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
268e87fd3eSjruoho.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
278e87fd3eSjruoho.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
288e87fd3eSjruoho.\" POSSIBILITY OF SUCH DAMAGE.
298e87fd3eSjruoho.\"
30*7bb35895Schristos.Dd December 4, 2012
318e87fd3eSjruoho.Dt SETBIT 9
328e87fd3eSjruoho.Os
338e87fd3eSjruoho.Sh NAME
348e87fd3eSjruoho.Nm setbit
358e87fd3eSjruoho.Nd macros related to bitmaps
368e87fd3eSjruoho.Sh SYNOPSIS
378e87fd3eSjruoho.In sys/param.h
388e87fd3eSjruoho.Ft void
398e87fd3eSjruoho.Fn setbit "array" "x"
408e87fd3eSjruoho.Ft void
418e87fd3eSjruoho.Fn clrbit "array" "x"
428e87fd3eSjruoho.Ft int
438e87fd3eSjruoho.Fn isset "array" "x"
448e87fd3eSjruoho.Ft int
458e87fd3eSjruoho.Fn isclr "array" "x"
468e87fd3eSjruoho.Sh DESCRIPTION
478e87fd3eSjruohoThe
488e87fd3eSjruoho.Nm
498e87fd3eSjruohofamily of macros operate with bitmaps, also known as bit arrays.
508e87fd3eSjruoho.Pp
518e87fd3eSjruohoIn a nutshell,
528e87fd3eSjruoho.Fn setbit
538e87fd3eSjruohosets the bit
548e87fd3eSjruoho.Fa x
558e87fd3eSjruohoin
568e87fd3eSjruoho.Fa array ,
578e87fd3eSjruoho.Fn clrbit
588e87fd3eSjruohoclears it,
598e87fd3eSjruoho.Fn isset
608e87fd3eSjruohotests whether
618e87fd3eSjruoho.Fa x
628e87fd3eSjruohois set, and
638e87fd3eSjruoho.Fn isclr
648e87fd3eSjruohoreturns 1 if
658e87fd3eSjruoho.Fa x
668e87fd3eSjruohois not set.
678e87fd3eSjruoho.Sh EXAMPLES
688e87fd3eSjruohoThe following example declares a buffer of 10 chars,
698e87fd3eSjruohotreating it as an array of 80 bits:
708e87fd3eSjruoho.Bd -literal -offset indent
718e87fd3eSjruohochar buf[10];
728e87fd3eSjruoho
738e87fd3eSjruoho\&...
748e87fd3eSjruoho
758e87fd3eSjruohosetbit(buf, 12);	/* set the fifth bit in the second byte */
768e87fd3eSjruoho.Ed
77bb3d11e4Sjruoho.Sh SEE ALSO
78*7bb35895Schristos.Xr bitmap 3 ,
79bb3d11e4Sjruoho.Xr bitstring 3
808e87fd3eSjruoho.Sh CAVEATS
818e87fd3eSjruohoThe number of valid bits in a given array is assumed to be multiple of
828e87fd3eSjruoho.Dv CHAR_BIT ,
838e87fd3eSjruohothe number of bits for smallest object that is not a bit-field.
84