1f359758cSJung-uk Kim /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
38a36da99SPedro F. Giffuni *
4f359758cSJung-uk Kim * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
5f359758cSJung-uk Kim * All rights reserved.
6f359758cSJung-uk Kim *
7f359758cSJung-uk Kim * Redistribution and use in source and binary forms, with or without
8f359758cSJung-uk Kim * modification, are permitted provided that the following conditions
9f359758cSJung-uk Kim * are met:
10f359758cSJung-uk Kim * 1. Redistributions of source code must retain the above copyright
11f359758cSJung-uk Kim * notice, this list of conditions and the following disclaimer.
12f359758cSJung-uk Kim * 2. Redistributions in binary form must reproduce the above copyright
13f359758cSJung-uk Kim * notice, this list of conditions and the following disclaimer in the
14f359758cSJung-uk Kim * documentation and/or other materials provided with the distribution.
15f359758cSJung-uk Kim *
16f359758cSJung-uk Kim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17f359758cSJung-uk Kim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18f359758cSJung-uk Kim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19f359758cSJung-uk Kim * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20f359758cSJung-uk Kim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f359758cSJung-uk Kim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22f359758cSJung-uk Kim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f359758cSJung-uk Kim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24f359758cSJung-uk Kim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25f359758cSJung-uk Kim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26f359758cSJung-uk Kim * SUCH DAMAGE.
27f359758cSJung-uk Kim */
28f359758cSJung-uk Kim
29f359758cSJung-uk Kim #include <sys/cdefs.h>
30f359758cSJung-uk Kim #include <sys/libkern.h>
31f359758cSJung-uk Kim
32f359758cSJung-uk Kim size_t
strnlen(const char * s,size_t maxlen)33f359758cSJung-uk Kim strnlen(const char *s, size_t maxlen)
34f359758cSJung-uk Kim {
35f359758cSJung-uk Kim size_t len;
36f359758cSJung-uk Kim
37f359758cSJung-uk Kim for (len = 0; len < maxlen; len++, s++) {
38f359758cSJung-uk Kim if (!*s)
39f359758cSJung-uk Kim break;
40f359758cSJung-uk Kim }
41f359758cSJung-uk Kim return (len);
42f359758cSJung-uk Kim }
43