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 	<<strcspn>>---count characters not in string
20 
21 INDEX
22 	strcspn
23 
24 SYNOPSIS
25 	size_t strcspn(const char *<[s1]>, const char *<[s2]>);
26 
27 DESCRIPTION
28 	This function computes the length of the initial part of
29 	the string pointed to by <[s1]> which consists entirely of
30 	characters <[NOT]> from the string pointed to by <[s2]>
31 	(excluding the terminating null character).
32 
33 RETURNS
34 	<<strcspn>> returns the length of the substring found.
35 
36 PORTABILITY
37 <<strcspn>> is ANSI C.
38 
39 <<strcspn>> requires no supporting OS subroutines.
40  */
41 
42 #include <string.h>
43 
44 size_t
strcspn(const char * s1,const char * s2)45 strcspn (const char *s1,
46 	const char *s2)
47 {
48   const char *s = s1;
49   const char *c;
50 
51   while (*s1)
52     {
53       for (c = s2; *c; c++)
54 	{
55 	  if (*s1 == *c)
56 	    break;
57 	}
58       if (*c)
59 	break;
60       s1++;
61     }
62 
63   return s1 - s;
64 }
65