From 8de49a149103da8372add16ae8e843ea65e03123 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Fri, 4 Feb 2022 15:08:10 +0000 Subject: [PATCH] Implemented strcspn --- photon/libc/include/string.h | 1 + photon/libc/string/strcspn.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 photon/libc/string/strcspn.c diff --git a/photon/libc/include/string.h b/photon/libc/include/string.h index 5d7822e..d0d58f3 100644 --- a/photon/libc/include/string.h +++ b/photon/libc/include/string.h @@ -20,6 +20,7 @@ extern char *strcpy(char *dest, const char *src); extern char *strncpy(char *dest, const char *src, size_t sz); extern char *strrchr(const char *s, int c); +extern size_t strcspn(const char *str1, const char *str2); extern char *strdup(const char *s); diff --git a/photon/libc/string/strcspn.c b/photon/libc/string/strcspn.c new file mode 100644 index 0000000..9220d63 --- /dev/null +++ b/photon/libc/string/strcspn.c @@ -0,0 +1,15 @@ +#include + +size_t strcspn(const char *str1, const char *str2) +{ + size_t i; + for (i = 0; str1[i]; i++) { + for (size_t ii = 0; str2[ii]; ii++) { + if (str1[i] == str2[ii]) { + return i; + } + } + } + + return i; +}