scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit b239791cf4effebb1916fa5723eabf71d0abcbf1
parent 960d97aae29fcd5e7d09bcc24b28cdef9472f712
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 23 Feb 2017 16:20:32 +0100

[libc] Add strcspn()

Diffstat:
Mlibc/src/Makefile | 2+-
Alibc/src/strcspn.c | 19+++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)

diff --git 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 @@ -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; +}