Revision: 338 Author: nieklinnenbank Date: Fri Sep 4 07:36:35 2009Log: Added strrchr() to search for the last occurrence of a character in a string.
http://code.google.com/p/freenos/source/detail?r=338 Added: /trunk/lib/libc/string/strrchr.c Modified: /trunk/lib/libc/string.h ======================================= --- /dev/null +++ /trunk/lib/libc/string/strrchr.c Fri Sep 4 07:36:35 2009 @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2009 Niek Linnenbank + * + * 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 3 of the License, or + * (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "string.h" + +char * strrchr(const char *s, int c) +{ + char *last = NULL; + + for ( ; *s ; s++) + { + if (*s == c) last = (char *) s; + } + return last; +} ======================================= --- /trunk/lib/libc/string.h Sat Jun 27 13:46:09 2009 +++ /trunk/lib/libc/string.h Fri Sep 4 07:36:35 2009 @@ -197,6 +197,20 @@ */ extern C char * strchr(const char *s, int c); +/** + * @brief String scanning operation. + * + * The strrchr() function shall locate the last occurrence of c + * (converted to a char) in the string pointed to by s. The terminating + * NUL character is considered to be part of the string. + * + * @param s String to search in. + * @param c Character to look for. + * @return Upon successful completion, strrchr() shall return a pointer + * to the byte or a null pointer if c does not occur in the string. + */ +extern C char * strrchr(const char *s, int c); + /** * @} */