xref: /netbsd-src/sys/arch/ia64/stand/common/strspn.c (revision 82357f6d420792564499086cb6440ad2fcce8410)
1*82357f6dSdsl /*	$NetBSD: strspn.c,v 1.2 2009/03/14 21:04:10 dsl Exp $	*/
2ba7cbe76Scherry 
3ba7cbe76Scherry /*
4ba7cbe76Scherry  * Copyright (c) 1989, 1993
5ba7cbe76Scherry  *	The Regents of the University of California.  All rights reserved.
6ba7cbe76Scherry  *
7ba7cbe76Scherry  * Redistribution and use in source and binary forms, with or without
8ba7cbe76Scherry  * modification, are permitted provided that the following conditions
9ba7cbe76Scherry  * are met:
10ba7cbe76Scherry  * 1. Redistributions of source code must retain the above copyright
11ba7cbe76Scherry  *    notice, this list of conditions and the following disclaimer.
12ba7cbe76Scherry  * 2. Redistributions in binary form must reproduce the above copyright
13ba7cbe76Scherry  *    notice, this list of conditions and the following disclaimer in the
14ba7cbe76Scherry  *    documentation and/or other materials provided with the distribution.
15ba7cbe76Scherry  * 3. Neither the name of the University nor the names of its contributors
16ba7cbe76Scherry  *    may be used to endorse or promote products derived from this software
17ba7cbe76Scherry  *    without specific prior written permission.
18ba7cbe76Scherry  *
19ba7cbe76Scherry  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20ba7cbe76Scherry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21ba7cbe76Scherry  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22ba7cbe76Scherry  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23ba7cbe76Scherry  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24ba7cbe76Scherry  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25ba7cbe76Scherry  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26ba7cbe76Scherry  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27ba7cbe76Scherry  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28ba7cbe76Scherry  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29ba7cbe76Scherry  * SUCH DAMAGE.
30ba7cbe76Scherry  */
31ba7cbe76Scherry 
32ba7cbe76Scherry #include <sys/cdefs.h>
33ba7cbe76Scherry #if defined(LIBC_SCCS) && !defined(lint)
34ba7cbe76Scherry #if 0
35ba7cbe76Scherry static char sccsid[] = "@(#)strspn.c	8.1 (Berkeley) 6/4/93";
36ba7cbe76Scherry #else
37*82357f6dSdsl __RCSID("$NetBSD: strspn.c,v 1.2 2009/03/14 21:04:10 dsl Exp $");
38ba7cbe76Scherry #endif
39ba7cbe76Scherry #endif /* LIBC_SCCS and not lint */
40ba7cbe76Scherry 
41ba7cbe76Scherry #include <sys/types.h>
42ba7cbe76Scherry 
43ba7cbe76Scherry #define _DIAGASSERT(x)	(void)0
44ba7cbe76Scherry 
45ba7cbe76Scherry /*
46ba7cbe76Scherry  * Span the string s2 (skip characters that are in s2).
47ba7cbe76Scherry  */
48ba7cbe76Scherry size_t
strspn(const char * s1,const char * s2)49*82357f6dSdsl strspn(const char *s1, const char *s2)
50ba7cbe76Scherry {
51ba7cbe76Scherry 	const char *p = s1, *spanp;
52ba7cbe76Scherry 	char c, sc;
53ba7cbe76Scherry 
54ba7cbe76Scherry 	_DIAGASSERT(s1 != NULL);
55ba7cbe76Scherry 	_DIAGASSERT(s2 != NULL);
56ba7cbe76Scherry 
57ba7cbe76Scherry 	/*
58ba7cbe76Scherry 	 * Skip any characters in s2, excluding the terminating \0.
59ba7cbe76Scherry 	 */
60ba7cbe76Scherry cont:
61ba7cbe76Scherry 	c = *p++;
62ba7cbe76Scherry 	for (spanp = s2; (sc = *spanp++) != 0;)
63ba7cbe76Scherry 		if (sc == c)
64ba7cbe76Scherry 			goto cont;
65ba7cbe76Scherry 	return (p - 1 - s1);
66ba7cbe76Scherry }
67