From afb85e9d6ca1de8f1ecb267e8c30b88ba4382820 Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Thu, 6 Jul 2000 07:16:59 +0000 Subject: Rework all the string handling. Make const stuff be constified. -Erik --- libc/string/strcspn.c | 72 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 27 deletions(-) (limited to 'libc/string/strcspn.c') diff --git a/libc/string/strcspn.c b/libc/string/strcspn.c index 619c8be6b..3630a1333 100644 --- a/libc/string/strcspn.c +++ b/libc/string/strcspn.c @@ -1,32 +1,50 @@ -/* strcspn.c */ +/* Copyright (C) 1991, 1994, 1996, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. -/* from Schumacher's Atari library, improved */ + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. -#include + The GNU C Library 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 + Library General Public License for more details. -size_t strcspn(string, set) -register char *string; -char *set; -/* - * Return the length of the sub-string of that consists - * entirely of characters not found in . The terminating '\0' - * in is not considered part of the match set. If the first - * character if is in , 0 is returned. - */ + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#if HAVE_CONFIG_H +# include +#endif + +#if defined _LIBC || HAVE_STRING_H +# include +#else +# include +# ifndef strchr +# define strchr index +# endif +#endif + +#undef strcspn + +/* Return the length of the maximum initial segment of S + which contains no characters from REJECT. */ +size_t +strcspn (s, reject) + const char *s; + const char *reject; { - register char *setptr; - char *start; - - start = string; - while (*string) - { - setptr = set; - do - if (*setptr == *string) - goto break2; - while (*setptr++); - ++string; - } -break2: - return string - start; + size_t count = 0; + + while (*s != '\0') + if (strchr (reject, *s++) == NULL) + ++count; + else + return count; + + return count; } -- cgit v1.2.3