xref: /freebsd/lib/libc/string/ffs.3 (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1.\" Copyright (c) 1990, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Chris Torek.
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.Dd October 17, 2015
31.Dt FFS 3
32.Os
33.Sh NAME
34.Nm ffs ,
35.Nm ffsl ,
36.Nm ffsll ,
37.Nm fls ,
38.Nm flsl ,
39.Nm flsll
40.Nd find first or last bit set in a bit string
41.Sh LIBRARY
42.Lb libc
43.Sh SYNOPSIS
44.In strings.h
45.Ft int
46.Fn ffs "int value"
47.Ft int
48.Fn ffsl "long value"
49.Ft int
50.Fn ffsll "long long value"
51.Ft int
52.Fn fls "int value"
53.Ft int
54.Fn flsl "long value"
55.Ft int
56.Fn flsll "long long value"
57.Sh DESCRIPTION
58The
59.Fn ffs ,
60.Fn ffsl
61and
62.Fn ffsll
63functions find the first (least significant) bit set
64in
65.Fa value
66and return the index of that bit.
67.Pp
68The
69.Fn fls ,
70.Fn flsl
71and
72.Fn flsll
73functions find the last (most significant) bit set in
74.Fa value
75and return the index of that bit.
76.Pp
77Bits are numbered starting at 1, the least significant bit.
78A return value of zero from any of these functions means that the
79argument was zero.
80.Sh SEE ALSO
81.Xr bitstring 3 ,
82.Xr bitset 9
83.Sh HISTORY
84The
85.Fn ffs
86function appeared in
87.Bx 4.3 .
88Its prototype existed previously in
89.In string.h
90before it was moved to
91.In strings.h
92for
93.St -p1003.1-2001
94compliance.
95.Pp
96The
97.Fn ffsl ,
98.Fn fls
99and
100.Fn flsl
101functions appeared in
102.Fx 5.3 .
103The
104.Fn ffsll
105and
106.Fn flsll
107functions appeared in
108.Fx 7.1 .
109