xref: /csrg-svn/lib/libc/string/strspn.c (revision 42190)
124190Skre /*
2*42190Sbostic  * Copyright (c) 1989 The Regents of the University of California.
334479Sbostic  * All rights reserved.
434479Sbostic  *
534479Sbostic  * Redistribution and use in source and binary forms are permitted
634831Sbostic  * provided that the above copyright notice and this paragraph are
734831Sbostic  * duplicated in all such forms and that any documentation,
834831Sbostic  * advertising materials, and other materials related to such
934831Sbostic  * distribution and use acknowledge that the software was developed
1034831Sbostic  * by the University of California, Berkeley.  The name of the
1134831Sbostic  * University may not be used to endorse or promote products derived
1234831Sbostic  * from this software without specific prior written permission.
1334831Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434831Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15*42190Sbostic  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1624190Skre  */
1724190Skre 
1826537Sdonn #if defined(LIBC_SCCS) && !defined(lint)
19*42190Sbostic static char sccsid[] = "@(#)strspn.c	5.6 (Berkeley) 05/17/90";
2034479Sbostic #endif /* LIBC_SCCS and not lint */
2124190Skre 
22*42190Sbostic #include <sys/stdc.h>
2342181Sbostic #include <string.h>
2442181Sbostic 
25*42190Sbostic /*
26*42190Sbostic  * Span the string s2 (skip characters that are in s2).
27*42190Sbostic  */
28*42190Sbostic size_t
29*42190Sbostic strspn(s1, s2)
30*42190Sbostic 	const char *s1;
31*42190Sbostic 	register const char *s2;
3224190Skre {
33*42190Sbostic 	register const char *p = s1, *spanp;
34*42190Sbostic 	register char c, sc;
3524190Skre 
36*42190Sbostic 	/*
37*42190Sbostic 	 * Skip any characters in s2, excluding the terminating \0.
38*42190Sbostic 	 */
39*42190Sbostic cont:
40*42190Sbostic 	c = *p++;
41*42190Sbostic 	for (spanp = s2; (sc = *spanp++) != 0;)
42*42190Sbostic 		if (sc == c)
43*42190Sbostic 			goto cont;
44*42190Sbostic 	return (p - 1 - s1);
4524190Skre }
46