From 48ef7704c03e7e554c05de01bf8d1d70c16cb6f4 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Wed, 20 Dec 2017 16:34:35 -0500 Subject: add libc building to agbcc. --- libc/misc/ffs.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 libc/misc/ffs.c (limited to 'libc/misc/ffs.c') diff --git a/libc/misc/ffs.c b/libc/misc/ffs.c new file mode 100644 index 0000000..e4afe7a --- /dev/null +++ b/libc/misc/ffs.c @@ -0,0 +1,42 @@ +/* +FUNCTION + <>---find first bit set in a word + +INDEX + ffs + +ANSI_SYNOPSIS + int ffs(int <[word]>); + +TRAD_SYNOPSIS + int ffs(<[word]>); + +DESCRIPTION + +<> returns the first bit set in a word. + +RETURNS +<> returns 0 if <[c]> is 0, 1 if <[c]> is odd, 2 if <[c]> is a multiple of +2, etc. + +PORTABILITY +<> is not ANSI C. + +No supporting OS subroutines are required. */ + +int +ffs (word) + int word; +{ + int i; + + if (!word) + return 0; + + i = 0; + for (;;) + { + if (((1 << i++) & word) != 0) + return i; + } +} -- cgit v1.2.3