strrchr.c revision 53492
1234285Sdim/* 2234285Sdim * Copyright (c) 1988, 1993 3353358Sdim * The Regents of the University of California. All rights reserved. 4353358Sdim * 5353358Sdim * Redistribution and use in source and binary forms, with or without 6234285Sdim * modification, are permitted provided that the following conditions 7234285Sdim * are met: 8234285Sdim * 1. Redistributions of source code must retain the above copyright 9234285Sdim * notice, this list of conditions and the following disclaimer. 10249423Sdim * 2. Redistributions in binary form must reproduce the above copyright 11249423Sdim * notice, this list of conditions and the following disclaimer in the 12249423Sdim * documentation and/or other materials provided with the distribution. 13234285Sdim * 3. All advertising materials mentioning features or use of this software 14234285Sdim * must display the following acknowledgement: 15327952Sdim * This product includes software developed by the University of 16327952Sdim * California, Berkeley and its contributors. 17327952Sdim * 4. Neither the name of the University nor the names of its contributors 18360784Sdim * may be used to endorse or promote products derived from this software 19234285Sdim * without specific prior written permission. 20309124Sdim * 21234285Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22234285Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23234285Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24234285Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25234285Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26234285Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27314564Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28314564Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29309124Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30234285Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31234285Sdim * SUCH DAMAGE. 32234285Sdim * 33276479Sdim * $FreeBSD: head/sys/libkern/rindex.c 53492 1999-11-21 04:26:48Z peter $ 34288943Sdim */ 35288943Sdim 36314564Sdim#include <sys/param.h> 37234285Sdim#include <sys/libkern.h> 38234285Sdim 39234285Sdimchar * 40234285Sdimrindex(p, ch) 41234285Sdim char *p; 42234285Sdim int ch; 43234285Sdim{ 44234285Sdim char *save; 45234285Sdim 46314564Sdim for (save = NULL;; ++p) { 47288943Sdim if (*p == ch) 48288943Sdim save = p; 49234285Sdim if (!*p) 50234285Sdim return(save); 51234285Sdim } 52234285Sdim /* NOTREACHED */ 53234285Sdim} 54234285Sdim 55234285Sdimconst char * 56234285Sdimc_rindex(p, ch) 57234285Sdim const char *p; 58234285Sdim int ch; 59234285Sdim{ 60249423Sdim const char *save; 61249423Sdim 62234285Sdim for (save = NULL;; ++p) { 63234285Sdim if (*p == ch) 64234285Sdim save = p; 65234285Sdim if (!*p) 66234285Sdim return(save); 67234285Sdim } 68234285Sdim /* NOTREACHED */ 69234285Sdim} 70234285Sdim