diff options
author | demostanis <demostanis@protonmail.com> | 2022-09-10 18:15:57 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-10-14 13:37:29 +0200 |
commit | 09a2db89c98d9eb7ab9d528608f9cc7929468872 (patch) | |
tree | c720fba4949892154b7874fe5a791847624429d2 /Userland/Libraries/LibC | |
parent | aa788581f2db9dc38ec022f9744bf5c7d214c50e (diff) | |
download | serenity-09a2db89c98d9eb7ab9d528608f9cc7929468872.zip |
LibC: Add ffs{,l,ll}
Those are wrappers around AK::bit_scan_forward().
Diffstat (limited to 'Userland/Libraries/LibC')
-rw-r--r-- | Userland/Libraries/LibC/strings.cpp | 19 | ||||
-rw-r--r-- | Userland/Libraries/LibC/strings.h | 3 |
2 files changed, 22 insertions, 0 deletions
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 <AK/BuiltinWrappers.h> #include <assert.h> #include <ctype.h> #include <string.h> @@ -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 |