From ec3c37d1d40d7b288584c234f4c3e7a600f2353d Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 3 Apr 2025 12:30:34 -0400 Subject: new libs --- lib/strncmp.c | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 lib/strncmp.c (limited to 'lib/strncmp.c') diff --git a/lib/strncmp.c b/lib/strncmp.c new file mode 100644 index 0000000..e890517 --- /dev/null +++ b/lib/strncmp.c @@ -0,0 +1,11 @@ +#include + +int strncmp(const char *restrict lhs, const char *restrict rhs, size_t n) +{ + const unsigned char *l = (void *)lhs, *r = (void *)rhs; + if (!n--) + return 0; + for (; *l && *r && n && *l == *r; l++, r++, n--) + ; + return *l - *r; +} -- cgit v1.2.3-freya