strrchr.c revision 123631
1224133Sdim/* 2224133Sdim * Copyright (c) 1988, 1993 3224133Sdim * The Regents of the University of California. All rights reserved. 4224133Sdim * 5224133Sdim * Redistribution and use in source and binary forms, with or without 6224133Sdim * modification, are permitted provided that the following conditions 7224133Sdim * are met: 8224133Sdim * 1. Redistributions of source code must retain the above copyright 9224133Sdim * notice, this list of conditions and the following disclaimer. 10224133Sdim * 2. Redistributions in binary form must reproduce the above copyright 11224133Sdim * notice, this list of conditions and the following disclaimer in the 12224133Sdim * documentation and/or other materials provided with the distribution. 13224133Sdim * 3. All advertising materials mentioning features or use of this software 14224133Sdim * must display the following acknowledgement: 15234353Sdim * This product includes software developed by the University of 16224133Sdim * California, Berkeley and its contributors. 17224133Sdim * 4. Neither the name of the University nor the names of its contributors 18234353Sdim * may be used to endorse or promote products derived from this software 19234353Sdim * without specific prior written permission. 20224133Sdim * 21224133Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22224133Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23224133Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24224133Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25224133Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26224133Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27224133Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28224133Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29224133Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30224133Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31224133Sdim * SUCH DAMAGE. 32 */ 33 34#if defined(LIBC_SCCS) && !defined(lint) 35static char sccsid[] = "@(#)rindex.c 8.1 (Berkeley) 6/4/93"; 36#endif /* LIBC_SCCS and not lint */ 37#include <sys/cdefs.h> 38__FBSDID("$FreeBSD: head/lib/libc/string/rindex.c 123631 2003-12-18 07:44:53Z jkh $"); 39 40#include <stddef.h> 41 42#ifdef STRRCHR 43#include <string.h> 44 45char * 46strrchr 47#else 48#include <strings.h> 49 50char * 51rindex 52#endif 53(const char *p, int ch) 54{ 55 char *save; 56 char c; 57 58 c = ch; 59 for (save = NULL;; ++p) { 60 if (*p == c) 61 save = (char *)p; 62 if (*p == '\0') 63 return (save); 64 } 65 /* NOTREACHED */ 66} 67