strrchr.c revision 92889
178828Sobrien/* 2104834Sobrien * Copyright (c) 1988, 1993 360484Sobrien * The Regents of the University of California. All rights reserved. 460484Sobrien * 589857Sobrien * Redistribution and use in source and binary forms, with or without 660484Sobrien * modification, are permitted provided that the following conditions 789857Sobrien * are met: 860484Sobrien * 1. Redistributions of source code must retain the above copyright 960484Sobrien * notice, this list of conditions and the following disclaimer. 1060484Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1160484Sobrien * notice, this list of conditions and the following disclaimer in the 1289857Sobrien * documentation and/or other materials provided with the distribution. 1360484Sobrien * 3. All advertising materials mentioning features or use of this software 1460484Sobrien * must display the following acknowledgement: 1560484Sobrien * This product includes software developed by the University of 1660484Sobrien * California, Berkeley and its contributors. 1760484Sobrien * 4. Neither the name of the University nor the names of its contributors 1889857Sobrien * may be used to endorse or promote products derived from this software 19218822Sdim * without specific prior written permission. 20218822Sdim * 2160484Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2260484Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2360484Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2460484Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2560484Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2660484Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2760484Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2860484Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2960484Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3060484Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3160484Sobrien * SUCH DAMAGE. 3260484Sobrien */ 3360484Sobrien 3460484Sobrien#if defined(LIBC_SCCS) && !defined(lint) 3560484Sobrienstatic char sccsid[] = "@(#)rindex.c 8.1 (Berkeley) 6/4/93"; 3660484Sobrien#endif /* LIBC_SCCS and not lint */ 3760484Sobrien#include <sys/cdefs.h> 3860484Sobrien__FBSDID("$FreeBSD: head/lib/libc/string/rindex.c 92889 2002-03-21 18:49:23Z obrien $"); 3960484Sobrien 4060484Sobrien#include <stddef.h> 4160484Sobrien#include <string.h> 4260484Sobrien 43104834Sobrienchar * 4460484Sobrien#ifdef STRRCHR 4560484Sobrienstrrchr(p, ch) 4660484Sobrien#else 4760484Sobrienrindex(p, ch) 4860484Sobrien#endif 4960484Sobrien const char *p; 5060484Sobrien int ch; 5160484Sobrien{ 5260484Sobrien char *save; 5360484Sobrien 5460484Sobrien for (save = NULL;; ++p) { 5560484Sobrien if (*p == ch) 5660484Sobrien save = (char *)p; 5760484Sobrien if (!*p) 5860484Sobrien return(save); 5960484Sobrien } 6060484Sobrien /* NOTREACHED */ 6160484Sobrien} 6260484Sobrien