lib: c: core: implement strchr and strcspn

This commit is contained in:
2026-03-25 20:21:28 +00:00
parent 96784f611f
commit 6787f28728
3 changed files with 35 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
#include <stddef.h>
char *strchr(const char *str, int c)
{
while (1) {
if (*str == c) {
return (char *)str;
}
if (*str == 0) {
break;
}
}
return NULL;
}
+15
View File
@@ -0,0 +1,15 @@
#include <stddef.h>
size_t strcspn(const char *dest, const char *src)
{
size_t i = 0;
for (i = 0; dest[i]; i++) {
for (size_t ii = 0; src[ii]; i++) {
if (dest[i] == src[ii]) {
return i;
}
}
}
return i;
}
+4
View File
@@ -8,6 +8,10 @@ extern const char *strerror_code(int errnum);
extern size_t strlen(const char *s); extern size_t strlen(const char *s);
extern size_t strcspn(const char *dest, const char *src);
extern char *strchr(const char *str, int c);
extern int strcmp(const char *s1, const char *s2); extern int strcmp(const char *s1, const char *s2);
extern int strncmp(const char *s1, const char *s2, unsigned long n); extern int strncmp(const char *s1, const char *s2, unsigned long n);