diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-07 20:10:31 +0100 |
| commit | fc00c656c96528112d05cf0edf8631bd5eaea446 (patch) | |
| tree | a6e0e6c588191a8bd1c64afc3b7a258e3e66c236 /lib/libc/strings | |
Add build system scaffolding and libc headers
Diffstat (limited to 'lib/libc/strings')
| -rw-r--r-- | lib/libc/strings/ffs.c | 14 | ||||
| -rw-r--r-- | lib/libc/strings/ffsl.c | 14 | ||||
| -rw-r--r-- | lib/libc/strings/ffsll.c | 14 | ||||
| -rw-r--r-- | lib/libc/strings/strcasecmp.c | 24 | ||||
| -rw-r--r-- | lib/libc/strings/strncasecmp.c | 32 |
5 files changed, 98 insertions, 0 deletions
diff --git a/lib/libc/strings/ffs.c b/lib/libc/strings/ffs.c new file mode 100644 index 00000000..3b836021 --- /dev/null +++ b/lib/libc/strings/ffs.c @@ -0,0 +1,14 @@ +int ffs(int i) +{ + if (i == 0) + return 0; + + int pos = 1; + unsigned int u = (unsigned int)i; + + while ((u & 1U) == 0U) { + u >>= 1; + pos++; + } + return pos; +} diff --git a/lib/libc/strings/ffsl.c b/lib/libc/strings/ffsl.c new file mode 100644 index 00000000..2f2e7d44 --- /dev/null +++ b/lib/libc/strings/ffsl.c @@ -0,0 +1,14 @@ +int ffsl(long i) +{ + if (i == 0) + return 0; + + int pos = 1; + unsigned long u = (unsigned long)i; + + while ((u & 1UL) == 0UL) { + u >>= 1; + pos++; + } + return pos; +} diff --git a/lib/libc/strings/ffsll.c b/lib/libc/strings/ffsll.c new file mode 100644 index 00000000..acfacb87 --- /dev/null +++ b/lib/libc/strings/ffsll.c @@ -0,0 +1,14 @@ +int ffsll(long long i) +{ + if (i == 0) + return 0; + + int pos = 1; + unsigned long long u = (unsigned long long)i; + + while ((u & 1ULL) == 0ULL) { + u >>= 1; + pos++; + } + return pos; +} diff --git a/lib/libc/strings/strcasecmp.c b/lib/libc/strings/strcasecmp.c new file mode 100644 index 00000000..90ccc59b --- /dev/null +++ b/lib/libc/strings/strcasecmp.c @@ -0,0 +1,24 @@ +#include <libc.h> +#include <ctype.h> + +int strcasecmp(const char *s1, const char *s2) +{ + unsigned char c1, c2; + + while (*s1 && *s2) { + c1 = (unsigned char)tolower((unsigned char)*s1); + c2 = (unsigned char)tolower((unsigned char)*s2); + if (c1 != c2) + return c1 - c2; + s1++; + s2++; + } + + return (unsigned char)tolower((unsigned char)*s1) - + (unsigned char)tolower((unsigned char)*s2); +} + +weak int strcasecmp_l(const char *s1, const char *s2, locale_t unused locale) +{ + return strcasecmp(s1, s2); +} diff --git a/lib/libc/strings/strncasecmp.c b/lib/libc/strings/strncasecmp.c new file mode 100644 index 00000000..679cf245 --- /dev/null +++ b/lib/libc/strings/strncasecmp.c @@ -0,0 +1,32 @@ +#include <libc.h> +#include <ctype.h> +#include <stddef.h> + +int strncasecmp(const char *s1, const char *s2, size_t n) +{ + unsigned char c1, c2; + + if (n == 0) + return 0; + + while (n-- > 0 && *s1 && *s2) { + c1 = (unsigned char)tolower((unsigned char)*s1); + c2 = (unsigned char)tolower((unsigned char)*s2); + if (c1 != c2) + return c1 - c2; + s1++; + s2++; + } + + if (n == (size_t)-1) + return 0; + + return (unsigned char)tolower((unsigned char)*s1) - + (unsigned char)tolower((unsigned char)*s2); +} + +weak int strncasecmp_l(const char *s1, const char *s2, size_t n, + locale_t unused locale) +{ + return strncasecmp(s1, s2, n); +} |
