Index: include/strings.h
===================================================================
RCS file: /cvsroot/src/include/strings.h,v
retrieving revision 1.13
diff -u -p -r1.13 strings.h
--- include/strings.h	28 Apr 2008 20:22:54 -0000	1.13
+++ include/strings.h	1 Jul 2009 20:17:04 -0000
@@ -51,6 +51,8 @@ int	 bcmp(const void *, const void *, si
 void	 bcopy(const void *, void *, size_t);
 void	 bzero(void *, size_t);
 int	 ffs(int);
+int	 ffsl(long);
+int	 ffsll(long long);
 char	*index(const char *, int);
 char	*rindex(const char *, int);
 int	 strcasecmp(const char *, const char *);
Index: lib/libc/shlib_version
===================================================================
RCS file: /cvsroot/src/lib/libc/shlib_version,v
retrieving revision 1.212
diff -u -p -r1.212 shlib_version
--- lib/libc/shlib_version	26 May 2009 08:04:11 -0000	1.212
+++ lib/libc/shlib_version	1 Jul 2009 20:17:04 -0000
@@ -35,4 +35,4 @@
 #   it's insufficient bitwidth to implement all ctype class.
 #   see isblank's comment in ctype.h.
 major=12
-minor=168
+minor=169
Index: lib/libc/string/Lint_ffs.c
===================================================================
RCS file: /cvsroot/src/lib/libc/string/Lint_ffs.c,v
retrieving revision 1.2
diff -u -p -r1.2 Lint_ffs.c
--- lib/libc/string/Lint_ffs.c	14 Jun 2000 06:49:07 -0000	1.2
+++ lib/libc/string/Lint_ffs.c	1 Jul 2009 20:17:05 -0000
@@ -9,8 +9,7 @@
 
 /*ARGSUSED*/
 int
-ffs(value)
-	int value;
+ffs(int value)
 {
-	return(0);
+	return 0;
 }
Index: lib/libc/string/Makefile.inc
===================================================================
RCS file: /cvsroot/src/lib/libc/string/Makefile.inc,v
retrieving revision 1.71
diff -u -p -r1.71 Makefile.inc
--- lib/libc/string/Makefile.inc	1 May 2009 17:27:01 -0000	1.71
+++ lib/libc/string/Makefile.inc	1 Jul 2009 20:17:05 -0000
@@ -4,7 +4,7 @@
 # string sources
 .PATH: ${ARCHDIR}/string ${.CURDIR}/string
 
-SRCS+=	bm.c stpcpy.c stpncpy.c \
+SRCS+=	bm.c ffsl.c ffsll.c stpcpy.c stpncpy.c \
 	strcasecmp.c strncasecmp.c strcasestr.c strcoll.c strdup.c \
 	strerror.c strlcat.c strlcpy.c strnlen.c \
 	strmode.c strsignal.c strtok.c \
Index: lib/libc/string/ffs.3
===================================================================
RCS file: /cvsroot/src/lib/libc/string/ffs.3,v
retrieving revision 1.10
diff -u -p -r1.10 ffs.3
--- lib/libc/string/ffs.3	7 Aug 2003 16:43:47 -0000	1.10
+++ lib/libc/string/ffs.3	1 Jul 2009 20:17:05 -0000
@@ -30,11 +30,13 @@
 .\"     from: @(#)ffs.3	8.2 (Berkeley) 4/19/94
 .\"	$NetBSD: ffs.3,v 1.10 2003/08/07 16:43:47 agc Exp $
 .\"
-.Dd April 19, 1994
+.Dd June 30, 2009
 .Dt FFS 3
 .Os
 .Sh NAME
 .Nm ffs
+.Nm ffsl
+.Nm ffsll
 .Nd find first bit set in a bit string
 .Sh LIBRARY
 .Lb libc
@@ -44,8 +46,11 @@
 .Fn ffs "int value"
 .Sh DESCRIPTION
 The
-.Fn ffs
-function finds the first bit set in
+.Fn ffs,
+.Fn ffsl,
+and
+.Fn ffsll
+functions finds the first bit set in
 .Fa value
 and returns the index of that bit.
 Bits are numbered starting from 1, starting at the right-most
@@ -58,3 +63,8 @@ The
 .Fn ffs
 function appeared in
 .Bx 4.3 .
+The
+.Fn ffsl
+.Fn ffsll
+functions appeared in
+.Nx 6.0 .
Index: lib/libc/string/ffsl.c
===================================================================
RCS file: lib/libc/string/ffsl.c
diff -N lib/libc/string/ffsl.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ lib/libc/string/ffsl.c	1 Jul 2009 20:17:05 -0000
@@ -0,0 +1,54 @@
+/*	$NetBSD: */
+
+/* 
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: $");
+
+#include <strings.h>
+
+/*
+ * Find First Set bit
+ */
+int
+ffsl(long mask)
+{
+#ifdef _LP64
+	/* 64bit version */
+	int bit;
+
+	bit = ffs((int)mask);
+	if (bit == 0) {
+		mask >>= 32;
+		bit = ffs((int)mask);
+		if (bit) bit += 32;
+	}
+	return bit;
+#else
+	/* 32bit version: assmue sizeof(long) == sizeof(int) */
+	return ffs(mask);
+#endif
+}
Index: lib/libc/string/ffsll.c
===================================================================
RCS file: lib/libc/string/ffsll.c
diff -N lib/libc/string/ffsll.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ lib/libc/string/ffsll.c	1 Jul 2009 20:17:05 -0000
@@ -0,0 +1,73 @@
+/*	$NetBSD: */
+
+/*
+ * Copyright (c) 2008 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: $");
+
+#include <strings.h>
+#include <inttypes.h>
+
+/*
+ * Find First Set bit
+ */
+int
+ffsll(long long mask)
+{
+#ifdef _LP64
+	/* 64bit version */
+
+	/*
+	 * See Knuth, The Art of Computer Programming, Volume 4, Chapter 7.1.3.
+	 */
+
+	static const char lookup[64] = {
+	     1,  2, 57,  3, 58, 50, 29,  4,
+	    62, 59, 43, 51, 39, 30, 18,  5,
+	    63, 48, 60, 37, 46, 44, 52, 23,
+	    54, 40, 34, 31, 25, 19, 13,  6,
+	    64, 56, 49, 28, 61, 42, 38, 17,
+	    47, 36, 45, 22, 53, 33, 24, 12,
+	    55, 27, 41, 16, 35, 21, 32, 11,
+	    26, 15, 20, 10, 14,  9,  8,  7
+	};
+	if (mask)  
+		return lookup[((uint64_t)mask * 0x03f79d71b4ca8b09ULL) >> 58];
+	else
+		return 0;
+#else
+	int bit;
+
+	/* 32bit version */
+	bit = ffs((int)mask);
+	if (bit == 0) {
+		mask >>= 32;
+		bit = ffs((int)mask);
+		if (bit) bit += 32;
+	}
+	return bit;
+#endif
+}