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 13:44:29 +08: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 13:44:29 +08:00
1994-10-01 12:48:44 +08: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 13:44:29 +08:00
1994-10-01 12:48:44 +08: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 13:44:29 +08:00
1997-02-04 11:26:31 +08:00
#if HAVE_CONFIG_H
1996-07-15 11:56:06 +08:00
# include <config.h>
1994-10-01 12:48:44 +08:00
#endif
1994-09-28 09:19:14 +08:00
#if defined _LIBC || HAVE_STRING_H
1996-07-15 11:56:06 +08:00
# include <string.h>
1994-10-01 12:48:44 +08:00
#else
1996-07-15 11:56:06 +08:00
# include <strings.h>
# ifndef strchr
# define strchr index
# endif
1994-10-01 12:48:44 +08:00
#endif
1992-11-01 13:44:29 +08:00
#undef strcspn
1997-02-18 23:12:41 +08:00
/* Return the length of the maximum initial segment of S
1992-11-01 13:44:29 +08:00
which contains no characters from REJECT. */
1994-10-01 12:48:44 +08:00
int
strcspn (s, reject)
const char *s;
const char *reject;
1992-11-01 13:44:29 +08:00
{
int count = 0;
1992-11-01 13:44:29 +08:00
while (*s != '\0')
1994-10-01 12:48:44 +08:00
if (strchr (reject, *s++) == 0)
1992-11-01 13:44:29 +08:00
++count;
else
return count;
return count;
}