1 /*- 2 * Copyright (c) 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Chris Torek. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 #if defined(LIBC_SCCS) && !defined(lint) 12 static char sccsid[] = "@(#)strcspn.c 8.1 (Berkeley) 06/04/93"; 13 #endif /* LIBC_SCCS and not lint */ 14 15 #include <sys/cdefs.h> 16 #include <string.h> 17 18 /* 19 * Span the complement of string s2. 20 */ 21 size_t 22 strcspn(s1, s2) 23 const char *s1; 24 register const char *s2; 25 { 26 register const char *p, *spanp; 27 register char c, sc; 28 29 /* 30 * Stop as soon as we find any character from s2. Note that there 31 * must be a NUL in s2; it suffices to stop when we find that, too. 32 */ 33 for (p = s1;;) { 34 c = *p++; 35 spanp = s2; 36 do { 37 if ((sc = *spanp++) == c) 38 return (p - 1 - s1); 39 } while (sc != 0); 40 } 41 /* NOTREACHED */ 42 } 43