flsl.c revision 124483
1124483Sdes/*-
2124483Sdes * Copyright (c) 1990, 1993
3124483Sdes *	The Regents of the University of California.  All rights reserved.
4124483Sdes *
5124483Sdes * Redistribution and use in source and binary forms, with or without
6124483Sdes * modification, are permitted provided that the following conditions
7124483Sdes * are met:
8124483Sdes * 1. Redistributions of source code must retain the above copyright
9124483Sdes *    notice, this list of conditions and the following disclaimer.
10124483Sdes * 2. Redistributions in binary form must reproduce the above copyright
11124483Sdes *    notice, this list of conditions and the following disclaimer in the
12124483Sdes *    documentation and/or other materials provided with the distribution.
13124483Sdes * 3. All advertising materials mentioning features or use of this software
14124483Sdes *    must display the following acknowledgement:
15124483Sdes *	This product includes software developed by the University of
16124483Sdes *	California, Berkeley and its contributors.
17124483Sdes * 4. Neither the name of the University nor the names of its contributors
18124483Sdes *    may be used to endorse or promote products derived from this software
19124483Sdes *    without specific prior written permission.
20124483Sdes *
21124483Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22124483Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23124483Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24124483Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25124483Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26124483Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27124483Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28124483Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29124483Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30124483Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31124483Sdes * SUCH DAMAGE.
32124483Sdes */
33124483Sdes
34124483Sdes#include <sys/cdefs.h>
35124483Sdes__FBSDID("$FreeBSD: head/lib/libc/string/flsl.c 124483 2004-01-13 16:05:47Z des $");
36124483Sdes
37124483Sdes#include <strings.h>
38124483Sdes
39124483Sdes/*
40124483Sdes * Find Last Set bit
41124483Sdes */
42124483Sdesint
43124483Sdesflsl(long mask)
44124483Sdes{
45124483Sdes	int bit;
46124483Sdes
47124483Sdes	if (mask == 0)
48124483Sdes		return (0);
49124483Sdes	for (bit = 1; mask != 1; bit++)
50124483Sdes		(unsigned long)mask >>= 1;
51124483Sdes	return (bit);
52124483Sdes}
53