142151Sbostic /*- 242151Sbostic * Copyright (c) 1990 The Regents of the University of California. 334479Sbostic * All rights reserved. 434479Sbostic * 542151Sbostic * This code is derived from software contributed to Berkeley by 642151Sbostic * Chris Torek. 742151Sbostic * 842151Sbostic * %sccs.include.redist.c% 924192Skre */ 1024192Skre 1126534Sdonn #if defined(LIBC_SCCS) && !defined(lint) 12*46144Sbostic static char sccsid[] = "@(#)strcspn.c 5.6 (Berkeley) 01/26/91"; 1334479Sbostic #endif /* LIBC_SCCS and not lint */ 1424192Skre 15*46144Sbostic #include <sys/cdefs.h> 1642151Sbostic #include <string.h> 1742151Sbostic 1842151Sbostic /* 1942151Sbostic * Span the complement of string s2. 2042151Sbostic */ 2142151Sbostic size_t 2242151Sbostic strcspn(s1, s2) 2342151Sbostic const char *s1; 2442151Sbostic register const char *s2; 2524192Skre { 2642151Sbostic register const char *p, *spanp; 2742151Sbostic register char c, sc; 2824192Skre 2942151Sbostic /* 3042151Sbostic * Stop as soon as we find any character from s2. Note that there 3142151Sbostic * must be a NUL in s2; it suffices to stop when we find that, too. 3242151Sbostic */ 3342151Sbostic for (p = s1;;) { 3442151Sbostic c = *p++; 3542151Sbostic spanp = s2; 3642151Sbostic do { 3742151Sbostic if ((sc = *spanp++) == c) 3842151Sbostic return (p - 1 - s1); 3942151Sbostic } while (sc != 0); 4024192Skre } 4142151Sbostic /* NOTREACHED */ 4224192Skre } 43