GNU shell utilities
[gnulib.git] / lib / strcspn.c
1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2
3 NOTE: The canonical source of this file is maintained with the GNU C Library.
4 Bugs can be reported to bug-glibc@prep.ai.mit.edu.
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include <ansidecl.h>
21 #include <string.h>
22
23
24 /* Return the length of the maximum inital segment of S
25    which contains no characters from REJECT.  */
26 size_t
27 DEFUN(strcspn, (s, reject),
28       register CONST char *s AND register CONST char *reject)
29 {
30   register size_t count = 0;
31
32   while (*s != '\0')
33     if (strchr(reject, *s++) == NULL)
34       ++count;
35     else
36       return count;
37
38   return count;
39 }