strrchr.c revision 229366
1139749Simp/*-
253790Sobrien * Copyright (c) 1988, 1993
353790Sobrien *	The Regents of the University of California.  All rights reserved.
453790Sobrien *
586266Sgroudier * Redistribution and use in source and binary forms, with or without
653790Sobrien * modification, are permitted provided that the following conditions
753790Sobrien * are met:
859743Sgroudier * 1. Redistributions of source code must retain the above copyright
959743Sgroudier *    notice, this list of conditions and the following disclaimer.
1053790Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1153790Sobrien *    notice, this list of conditions and the following disclaimer in the
1253790Sobrien *    documentation and/or other materials provided with the distribution.
1353790Sobrien * 4. Neither the name of the University nor the names of its contributors
1453790Sobrien *    may be used to endorse or promote products derived from this software
1553790Sobrien *    without specific prior written permission.
1653790Sobrien *
1753790Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1853790Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1953790Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2053790Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2153790Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2253790Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2353790Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2453790Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2553790Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2653790Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2753790Sobrien * SUCH DAMAGE.
2853790Sobrien */
2953790Sobrien
3053790Sobrien#include <sys/cdefs.h>
3153790Sobrien__FBSDID("$FreeBSD: head/sys/libkern/strrchr.c 229366 2012-01-03 07:05:30Z ed $");
3253790Sobrien
3353790Sobrien#include <sys/param.h>
3453790Sobrien#include <sys/libkern.h>
3553790Sobrien
3653790Sobrienchar *
3753790Sobrienstrrchr(const char *p, int ch)
3853790Sobrien{
3953790Sobrien	union {
4053790Sobrien		const char *cp;
4153790Sobrien		char *p;
4253790Sobrien	} u;
4353790Sobrien	char *save;
4453790Sobrien
4553790Sobrien	u.cp = p;
4653790Sobrien	for (save = NULL;; ++u.p) {
4753790Sobrien		if (*u.p == ch)
4853790Sobrien			save = u.p;
4953790Sobrien		if (*u.p == '\0')
5053790Sobrien			return(save);
5153790Sobrien	}
5253790Sobrien	/* NOTREACHED */
5353790Sobrien}
5453790Sobrien