xref: /openbsd-src/sys/lib/libkern/strrchr.c (revision b5be37d2a6fbef83b90ca99497343fa8dbb0f3fc)
1*b5be37d2Sderaadt /*	$OpenBSD: strrchr.c,v 1.2 2014/06/10 04:16:57 deraadt Exp $	*/
24d6af78aSderaadt 
34d6af78aSderaadt /*
44d6af78aSderaadt  * Copyright (c) 2004 Daniel Hartmeier
54d6af78aSderaadt  * All rights reserved.
64d6af78aSderaadt  *
74d6af78aSderaadt  * Redistribution and use in source and binary forms, with or without
84d6af78aSderaadt  * modification, are permitted provided that the following conditions
94d6af78aSderaadt  * are met:
104d6af78aSderaadt  *
114d6af78aSderaadt  *    - Redistributions of source code must retain the above copyright
124d6af78aSderaadt  *      notice, this list of conditions and the following disclaimer.
134d6af78aSderaadt  *    - Redistributions in binary form must reproduce the above
144d6af78aSderaadt  *      copyright notice, this list of conditions and the following
154d6af78aSderaadt  *      disclaimer in the documentation and/or other materials provided
164d6af78aSderaadt  *      with the distribution.
174d6af78aSderaadt  *
184d6af78aSderaadt  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
194d6af78aSderaadt  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
204d6af78aSderaadt  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
214d6af78aSderaadt  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
224d6af78aSderaadt  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
234d6af78aSderaadt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
244d6af78aSderaadt  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
254d6af78aSderaadt  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
264d6af78aSderaadt  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
274d6af78aSderaadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
284d6af78aSderaadt  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
294d6af78aSderaadt  * POSSIBILITY OF SUCH DAMAGE.
304d6af78aSderaadt  *
314d6af78aSderaadt  */
324d6af78aSderaadt 
334d6af78aSderaadt #include <lib/libkern/libkern.h>
344d6af78aSderaadt #define NULL	((char *)0)
354d6af78aSderaadt 
364d6af78aSderaadt char *
strrchr(const char * s,int c)374d6af78aSderaadt strrchr(const char *s, int c)
384d6af78aSderaadt {
394d6af78aSderaadt 	char *t = NULL;
404d6af78aSderaadt 
414d6af78aSderaadt 	while (*s) {
424d6af78aSderaadt 		if (*s == c)
434d6af78aSderaadt 			t = (char *)s;
444d6af78aSderaadt 		s++;
454d6af78aSderaadt 	}
464d6af78aSderaadt 	return (t);
474d6af78aSderaadt }
48