summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/strings.h2
-rw-r--r--lib/libc/string/Makefile.inc6
-rw-r--r--lib/libc/string/Symbol.map2
-rw-r--r--lib/libc/string/ffs.326
-rw-r--r--lib/libc/string/ffsll.c48
-rw-r--r--lib/libc/string/flsll.c48
6 files changed, 124 insertions, 8 deletions
diff --git a/include/strings.h b/include/strings.h
index 4b19d0e..f6a0024 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -44,8 +44,10 @@ void bzero(void *, size_t); /* LEGACY */
int ffs(int) __pure2;
#ifdef __BSD_VISIBLE
int ffsl(long) __pure2;
+int ffsll(long long) __pure2;
int fls(int) __pure2;
int flsl(long) __pure2;
+int flsll(long long) __pure2;
#endif
char *index(const char *, int) __pure; /* LEGACY */
char *rindex(const char *, int) __pure; /* LEGACY */
diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc
index 9e5f0da..5963fc9 100644
--- a/lib/libc/string/Makefile.inc
+++ b/lib/libc/string/Makefile.inc
@@ -6,8 +6,8 @@
CFLAGS+= -I${.CURDIR}/locale
# machine-independent string sources
-MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffsl.c fls.c flsl.c index.c memccpy.c \
- memchr.c memrchr.c memcmp.c \
+MISRCS+=bcmp.c bcopy.c bzero.c ffs.c ffsl.c ffsll.c fls.c flsl.c flsll.c \
+ index.c memccpy.c memchr.c memrchr.c memcmp.c \
memcpy.c memmem.c memmove.c memset.c rindex.c stpcpy.c strcasecmp.c \
strcat.c strchr.c strcmp.c strcoll.c strcpy.c strcspn.c strdup.c \
strerror.c strlcat.c strlcpy.c strlen.c strmode.c strncat.c strncmp.c \
@@ -38,6 +38,8 @@ MAN+= bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 memccpy.3 memchr.3 \
MLINKS+=ffs.3 ffsl.3
MLINKS+=ffs.3 fls.3
MLINKS+=ffs.3 flsl.3
+MLINKS+=ffs.3 ffsll.3
+MLINKS+=ffs.3 flsll.3
MLINKS+=index.3 rindex.3
MLINKS+=memchr.3 memrchr.3
MLINKS+=strcasecmp.3 strncasecmp.3
diff --git a/lib/libc/string/Symbol.map b/lib/libc/string/Symbol.map
index d034ecc..e307c7f 100644
--- a/lib/libc/string/Symbol.map
+++ b/lib/libc/string/Symbol.map
@@ -78,6 +78,8 @@ FBSD_1.0 {
};
FBSD_1.1 {
+ ffsll;
+ flsll;
memrchr;
};
diff --git a/lib/libc/string/ffs.3 b/lib/libc/string/ffs.3
index 55daae4..e66d7eb 100644
--- a/lib/libc/string/ffs.3
+++ b/lib/libc/string/ffs.3
@@ -30,14 +30,16 @@
.\" @(#)ffs.3 8.2 (Berkeley) 4/19/94
.\" $FreeBSD$
.\"
-.Dd October 12, 2006
+.Dd October 26, 2008
.Dt FFS 3
.Os
.Sh NAME
.Nm ffs ,
.Nm ffsl ,
+.Nm ffsll ,
.Nm fls ,
-.Nm flsl
+.Nm flsl ,
+.Nm flsll
.Nd find first or last bit set in a bit string
.Sh LIBRARY
.Lb libc
@@ -48,14 +50,19 @@
.Ft int
.Fn ffsl "long value"
.Ft int
+.Ft int
+.Fn ffsll "long long value"
.Fn fls "int value"
.Ft int
.Fn flsl "long value"
+.Ft int
+.Fn flsll "long long value"
.Sh DESCRIPTION
The
-.Fn ffs
-and
+.Fn ffs ,
.Fn ffsl
+and
+.Fn ffsll
functions find the first bit set
(beginning with the least significant bit)
in
@@ -63,9 +70,10 @@ in
and return the index of that bit.
.Pp
The
-.Fn fls
-and
+.Fn fls ,
.Fn flsl
+and
+.Fn flsll
functions find the last bit set in
.Fa value
and return the index of that bit.
@@ -95,3 +103,9 @@ and
.Fn flsl
functions appeared in
.Fx 5.3 .
+The
+.Fn ffsll
+and
+.Fn flsll
+functions appeared in
+.Fx 8.0 .
diff --git a/lib/libc/string/ffsll.c b/lib/libc/string/ffsll.c
new file mode 100644
index 0000000..59e03bc
--- /dev/null
+++ b/lib/libc/string/ffsll.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. 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.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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>
+__FBSDID("$FreeBSD$");
+
+#include <strings.h>
+
+/*
+ * Find First Set bit
+ */
+int
+ffsll(long long mask)
+{
+ int bit;
+
+ if (mask == 0)
+ return (0);
+ for (bit = 1; !(mask & 1); bit++)
+ mask = (unsigned long long)mask >> 1;
+ return (bit);
+}
diff --git a/lib/libc/string/flsll.c b/lib/libc/string/flsll.c
new file mode 100644
index 0000000..ab55627
--- /dev/null
+++ b/lib/libc/string/flsll.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. 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.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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>
+__FBSDID("$FreeBSD$");
+
+#include <strings.h>
+
+/*
+ * Find Last Set bit
+ */
+int
+flsll(long long mask)
+{
+ int bit;
+
+ if (mask == 0)
+ return (0);
+ for (bit = 1; mask != 1; bit++)
+ mask = (unsigned long long)mask >> 1;
+ return (bit);
+}
OpenPOWER on IntegriCloud