diff --git a/lib/libc/core/string/strchr.c b/lib/libc/core/string/strchr.c new file mode 100644 index 0000000..7822059 --- /dev/null +++ b/lib/libc/core/string/strchr.c @@ -0,0 +1,16 @@ +#include + +char *strchr(const char *str, int c) +{ + while (1) { + if (*str == c) { + return (char *)str; + } + + if (*str == 0) { + break; + } + } + + return NULL; +} diff --git a/lib/libc/core/string/strcspn.c b/lib/libc/core/string/strcspn.c new file mode 100644 index 0000000..53107d2 --- /dev/null +++ b/lib/libc/core/string/strcspn.c @@ -0,0 +1,15 @@ +#include + +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; +} diff --git a/lib/libc/include/string.h b/lib/libc/include/string.h index 0a8cd0b..b4e2b44 100644 --- a/lib/libc/include/string.h +++ b/lib/libc/include/string.h @@ -8,6 +8,10 @@ extern const char *strerror_code(int errnum); 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 strncmp(const char *s1, const char *s2, unsigned long n);