shithub: scc

Download patch

ref: fe11ef11c059f7beeb45f605c4a706d4088c3168
parent: 84af3abc43c0cb42d5ad3895fff7c99a6e1efc21
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Feb 23 11:20:32 EST 2017

[libc] Add strcspn()

--- 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 \
--- /dev/null
+++ b/libc/src/strcspn.c
@@ -1,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;
+}