1 /*
2 Copyright (c) 1994 Cygnus Support.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms are permitted
6 provided that the above copyright notice and this paragraph are
7 duplicated in all such forms and that any documentation,
8 and/or other materials related to such
9 distribution and use acknowledge that the software was developed
10 at Cygnus Support, Inc.  Cygnus Support, Inc. may not be used to
11 endorse or promote products derived from this software without
12 specific prior written permission.
13 THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 /*
18 FUNCTION
19 	<<strspn>>---find initial match
20 
21 INDEX
22 	strspn
23 
24 SYNOPSIS
25 	#include <string.h>
26 	size_t strspn(const char *<[s1]>, const char *<[s2]>);
27 
28 DESCRIPTION
29 	This function computes the length of the initial segment of
30 	the string pointed to by <[s1]> which consists entirely of
31 	characters from the string pointed to by <[s2]> (excluding the
32 	terminating null character).
33 
34 RETURNS
35 	<<strspn>> returns the length of the segment found.
36 
37 PORTABILITY
38 <<strspn>> is ANSI C.
39 
40 <<strspn>> requires no supporting OS subroutines.
41 
42 QUICKREF
43 	strspn ansi pure
44 */
45 
46 #include <string.h>
47 
48 size_t
strspn(const char * s1,const char * s2)49 strspn (const char *s1,
50 	const char *s2)
51 {
52   const char *s = s1;
53   const char *c;
54 
55   while (*s1)
56     {
57       for (c = s2; *c; c++)
58 	{
59 	  if (*s1 == *c)
60 	    goto found;
61 	}
62       if (*c == '\0')
63 	break;
64 found:
65       s1++;
66     }
67 
68   return s1 - s;
69 }
70