1*a9abaa49Schristos /* $NetBSD: strchrnul.c,v 1.1 2016/10/12 20:01:40 christos Exp $ */
2*a9abaa49Schristos
3*a9abaa49Schristos /*-
4*a9abaa49Schristos * Copyright (c) 1990, 1993
5*a9abaa49Schristos * The Regents of the University of California. All rights reserved.
6*a9abaa49Schristos *
7*a9abaa49Schristos * Redistribution and use in source and binary forms, with or without
8*a9abaa49Schristos * modification, are permitted provided that the following conditions
9*a9abaa49Schristos * are met:
10*a9abaa49Schristos * 1. Redistributions of source code must retain the above copyright
11*a9abaa49Schristos * notice, this list of conditions and the following disclaimer.
12*a9abaa49Schristos * 2. Redistributions in binary form must reproduce the above copyright
13*a9abaa49Schristos * notice, this list of conditions and the following disclaimer in the
14*a9abaa49Schristos * documentation and/or other materials provided with the distribution.
15*a9abaa49Schristos * 3. Neither the name of the University nor the names of its contributors
16*a9abaa49Schristos * may be used to endorse or promote products derived from this software
17*a9abaa49Schristos * without specific prior written permission.
18*a9abaa49Schristos *
19*a9abaa49Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*a9abaa49Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*a9abaa49Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*a9abaa49Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*a9abaa49Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*a9abaa49Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*a9abaa49Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*a9abaa49Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*a9abaa49Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*a9abaa49Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*a9abaa49Schristos * SUCH DAMAGE.
30*a9abaa49Schristos */
31*a9abaa49Schristos
32*a9abaa49Schristos #include <sys/cdefs.h>
33*a9abaa49Schristos #if defined(LIBC_SCCS) && !defined(lint)
34*a9abaa49Schristos #if 0
35*a9abaa49Schristos static char sccsid[] = "@(#)index.c 8.1 (Berkeley) 6/4/93";
36*a9abaa49Schristos #else
37*a9abaa49Schristos __RCSID("$NetBSD: strchrnul.c,v 1.1 2016/10/12 20:01:40 christos Exp $");
38*a9abaa49Schristos #endif
39*a9abaa49Schristos #endif /* LIBC_SCCS and not lint */
40*a9abaa49Schristos
41*a9abaa49Schristos #if !defined(_KERNEL) && !defined(_STANDALONE)
42*a9abaa49Schristos #include "namespace.h"
43*a9abaa49Schristos #include <assert.h>
44*a9abaa49Schristos #include <string.h>
45*a9abaa49Schristos #else
46*a9abaa49Schristos #include <lib/libkern/libkern.h>
47*a9abaa49Schristos #endif
48*a9abaa49Schristos
49*a9abaa49Schristos char *
strchrnul(const char * p,int ch)50*a9abaa49Schristos strchrnul(const char *p, int ch)
51*a9abaa49Schristos {
52*a9abaa49Schristos const char cmp = ch;
53*a9abaa49Schristos _DIAGASSERT(p != NULL);
54*a9abaa49Schristos
55*a9abaa49Schristos for (;; ++p) {
56*a9abaa49Schristos if (*p == cmp || !*p) {
57*a9abaa49Schristos /* LINTED const cast-away */
58*a9abaa49Schristos return __UNCONST(p);
59*a9abaa49Schristos }
60*a9abaa49Schristos }
61*a9abaa49Schristos /* NOTREACHED */
62*a9abaa49Schristos }
63