commit 53999a7b176719d14aaf4a2d00ff0647e1ce78b6
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Thu Feb 23 16:20:32 2017 +0100
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Thu Feb 23 16:20:32 2017 +0100

    [libc] Add strcspn()

diff --git a/libc/src/Makefile b/libc/src/Makefile
index e401f13..5d5484c 100644
--- a/libc/src/Makefile
+++ b/libc/src/Makefile
@@ -3,7 +3,7 @@
 
 LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
           strrchr.o strcat.o strncmp.o strncpy.o strncat.o strcoll.o \
-          strxfrm.o strtok.o strstr.o strspn.o \
+          strxfrm.o strtok.o strstr.o strspn.o strcspn.o \
           memset.o memcpy.o memmove.o memcmp.o memchr.o \
           isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \
           isgraph.o islower.o isprint.o ispunct.o isspace.o isupper.o \
diff --git a/libc/src/strcspn.c b/libc/src/strcspn.c
new file mode 100644
index 0000000..2b94db1
--- /dev/null
+++ b/libc/src/strcspn.c
@@ -0,0 +1,19 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+
+size_t
+strcspn(const char *s1, const char *s2)
+{
+        size_t n;
+        int c;
+       const char *p;
+
+        for (n = 0; c = *s1++; ++n) {
+                for (p = s2; *p && *p != c; ++p)
+                        /* nothing */;
+                if (*p == c)
+                        break;
+        }
+        return n;
+}

Reply via email to