From fc00c656c96528112d05cf0edf8631bd5eaea446 Mon Sep 17 00:00:00 2001 From: Kacper Date: Sun, 7 Dec 2025 20:10:31 +0100 Subject: Add build system scaffolding and libc headers --- lib/libc/strings/ffs.c | 14 ++++++++++++++ lib/libc/strings/ffsl.c | 14 ++++++++++++++ lib/libc/strings/ffsll.c | 14 ++++++++++++++ lib/libc/strings/strcasecmp.c | 24 ++++++++++++++++++++++++ lib/libc/strings/strncasecmp.c | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+) create mode 100644 lib/libc/strings/ffs.c create mode 100644 lib/libc/strings/ffsl.c create mode 100644 lib/libc/strings/ffsll.c create mode 100644 lib/libc/strings/strcasecmp.c create mode 100644 lib/libc/strings/strncasecmp.c (limited to 'lib/libc/strings') 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 +#include + +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 +#include +#include + +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); +} -- cgit v1.2.3