1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-19 18:26:32 +02:00
Files
coreutils/lib/strcspn.c

53 lines
1.4 KiB
C
Raw Normal View History

/* Copyright (C) 1991, 1994, 1996, 1997 Free Software Foundation, Inc.
1992-11-01 05:44:29 +00:00
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
1992-11-01 05:44:29 +00:00
1994-10-01 04:48:44 +00:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
1992-11-01 05:44:29 +00:00
1994-10-01 04:48:44 +00:00
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA. */
1992-11-01 05:44:29 +00:00
1997-02-04 03:26:31 +00:00
#if HAVE_CONFIG_H
1996-07-15 03:56:06 +00:00
# include <config.h>
1994-10-01 04:48:44 +00:00
#endif
1994-09-28 01:19:14 +00:00
#if defined _LIBC || HAVE_STRING_H
1996-07-15 03:56:06 +00:00
# include <string.h>
1994-10-01 04:48:44 +00:00
#else
1996-07-15 03:56:06 +00:00
# include <strings.h>
# ifndef strchr
# define strchr index
# endif
1994-10-01 04:48:44 +00:00
#endif
1992-11-01 05:44:29 +00:00
#undef strcspn
1997-02-18 15:12:41 +00:00
/* Return the length of the maximum initial segment of S
1992-11-01 05:44:29 +00:00
which contains no characters from REJECT. */
1994-10-01 04:48:44 +00:00
int
strcspn (s, reject)
const char *s;
const char *reject;
1992-11-01 05:44:29 +00:00
{
int count = 0;
1992-11-01 05:44:29 +00:00
while (*s != '\0')
1994-10-01 04:48:44 +00:00
if (strchr (reject, *s++) == 0)
1992-11-01 05:44:29 +00:00
++count;
else
return count;
return count;
}