summaryrefslogtreecommitdiff
path: root/sys/src/ape/lib/bsd/ffs.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/ape/lib/bsd/ffs.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/ape/lib/bsd/ffs.c')
-rwxr-xr-xsys/src/ape/lib/bsd/ffs.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/sys/src/ape/lib/bsd/ffs.c b/sys/src/ape/lib/bsd/ffs.c
new file mode 100755
index 000000000..508345365
--- /dev/null
+++ b/sys/src/ape/lib/bsd/ffs.c
@@ -0,0 +1,23 @@
+/* Find the first set bit
+ * i.e. least signifigant 1 bit:
+ * 0 => 0
+ * 1 => 1
+ * 2 => 2
+ * 3 => 1
+ * 4 => 3
+ */
+
+int
+ffs(unsigned int mask)
+{
+ int i;
+
+ if (!mask)
+ return 0;
+ i = 1;
+ while (!(mask & 1)){
+ i++;
+ mask = mask >> 1;
+ }
+ return i;
+}