xref: /csrg-svn/lib/libc/string/strcspn.c (revision 42151)
1*42151Sbostic /*-
2*42151Sbostic  * Copyright (c) 1990 The Regents of the University of California.
334479Sbostic  * All rights reserved.
434479Sbostic  *
5*42151Sbostic  * This code is derived from software contributed to Berkeley by
6*42151Sbostic  * Chris Torek.
7*42151Sbostic  *
8*42151Sbostic  * %sccs.include.redist.c%
924192Skre  */
1024192Skre 
1126534Sdonn #if defined(LIBC_SCCS) && !defined(lint)
12*42151Sbostic static char sccsid[] = "@(#)strcspn.c	5.5 (Berkeley) 05/16/90";
1334479Sbostic #endif /* LIBC_SCCS and not lint */
1424192Skre 
15*42151Sbostic #include <sys/stdc.h>
16*42151Sbostic #include <string.h>
17*42151Sbostic 
18*42151Sbostic /*
19*42151Sbostic  * Span the complement of string s2.
20*42151Sbostic  */
21*42151Sbostic size_t
22*42151Sbostic strcspn(s1, s2)
23*42151Sbostic 	const char *s1;
24*42151Sbostic 	register const char *s2;
2524192Skre {
26*42151Sbostic 	register const char *p, *spanp;
27*42151Sbostic 	register char c, sc;
2824192Skre 
29*42151Sbostic 	/*
30*42151Sbostic 	 * Stop as soon as we find any character from s2.  Note that there
31*42151Sbostic 	 * must be a NUL in s2; it suffices to stop when we find that, too.
32*42151Sbostic 	 */
33*42151Sbostic 	for (p = s1;;) {
34*42151Sbostic 		c = *p++;
35*42151Sbostic 		spanp = s2;
36*42151Sbostic 		do {
37*42151Sbostic 			if ((sc = *spanp++) == c)
38*42151Sbostic 				return (p - 1 - s1);
39*42151Sbostic 		} while (sc != 0);
4024192Skre 	}
41*42151Sbostic 	/* NOTREACHED */
4224192Skre }
43