From d0a041e7e8e5d26b530855dc75f35733b334ee54 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 2 Sep 2015 17:30:24 +0200 Subject: add ffs functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- include/strings.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'include') diff --git a/include/strings.h b/include/strings.h index 224c9a4..7a02d1e 100644 --- a/include/strings.h +++ b/include/strings.h @@ -145,6 +145,34 @@ char* rindex(const char*, int) __GCC_ONLY(__attribute__((warn_unused_result, nonnull, pure))); +/** + * Find the first set bit in an integer. + * + * @param i The integer + * @return The value of the least significant set bit, zero if none. + */ +int ffs(int) + __GCC_ONLY(__attribute__((warn_unused_result, const))); + +/** + * Find the first set bit in an integer. + * + * @param i The integer + * @return The value of the least significant set bit, zero if none. + */ +int ffsl(long) + __GCC_ONLY(__attribute__((warn_unused_result, const))); + +/** + * Find the first set bit in an integer. + * + * @param i The integer + * @return The value of the least significant set bit, zero if none. + */ +int ffsll(long long) + __GCC_ONLY(__attribute__((warn_unused_result, const))); + + #endif -- cgit v1.2.3-70-g09d2