diff --git a/Userland/Libraries/LibC/strings.cpp b/Userland/Libraries/LibC/strings.cpp index 0937cc2e1a..0614719335 100644 --- a/Userland/Libraries/LibC/strings.cpp +++ b/Userland/Libraries/LibC/strings.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -51,4 +52,22 @@ int strncasecmp(char const* s1, char const* s2, size_t n) } while (--n); return 0; } + +// https://pubs.opengroup.org/onlinepubs/009696799/functions/ffs.html +int ffs(int i) +{ + return bit_scan_forward(i); +} + +// https://linux.die.net/man/3/ffsl (GNU extension) +int ffsl(long int i) +{ + return bit_scan_forward(i); +} + +// https://linux.die.net/man/3/ffsll (GNU extension) +int ffsll(long long int i) +{ + return bit_scan_forward(i); +} } diff --git a/Userland/Libraries/LibC/strings.h b/Userland/Libraries/LibC/strings.h index 1805bc887c..a87f8ea032 100644 --- a/Userland/Libraries/LibC/strings.h +++ b/Userland/Libraries/LibC/strings.h @@ -15,5 +15,8 @@ int strcasecmp(char const*, char const*); int strncasecmp(char const*, char const*, size_t); void bzero(void*, size_t); void bcopy(void const*, void*, size_t); +int ffs(int); +int ffsl(long int); +int ffsll(long long int); __END_DECLS