1*0a6a1f1dSLionel Sambuc /* $NetBSD: strnlen.c,v 1.2 2014/01/09 11:25:11 apb Exp $ */
26b882151SKees Jongenburger
36b882151SKees Jongenburger /*-
46b882151SKees Jongenburger * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
56b882151SKees Jongenburger * All rights reserved.
66b882151SKees Jongenburger *
76b882151SKees Jongenburger * Redistribution and use in source and binary forms, with or without
86b882151SKees Jongenburger * modification, are permitted provided that the following conditions
96b882151SKees Jongenburger * are met:
106b882151SKees Jongenburger * 1. Redistributions of source code must retain the above copyright
116b882151SKees Jongenburger * notice, this list of conditions and the following disclaimer.
126b882151SKees Jongenburger * 2. Redistributions in binary form must reproduce the above copyright
136b882151SKees Jongenburger * notice, this list of conditions and the following disclaimer in the
146b882151SKees Jongenburger * documentation and/or other materials provided with the distribution.
156b882151SKees Jongenburger *
166b882151SKees Jongenburger * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
176b882151SKees Jongenburger * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
186b882151SKees Jongenburger * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
196b882151SKees Jongenburger * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
206b882151SKees Jongenburger * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
216b882151SKees Jongenburger * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
226b882151SKees Jongenburger * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
236b882151SKees Jongenburger * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
246b882151SKees Jongenburger * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
256b882151SKees Jongenburger * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
266b882151SKees Jongenburger * SUCH DAMAGE.
276b882151SKees Jongenburger */
286b882151SKees Jongenburger
29*0a6a1f1dSLionel Sambuc #if HAVE_NBTOOL_CONFIG_H
30*0a6a1f1dSLionel Sambuc #include "nbtool_config.h"
31*0a6a1f1dSLionel Sambuc #endif
32*0a6a1f1dSLionel Sambuc
336b882151SKees Jongenburger #include <sys/cdefs.h>
346b882151SKees Jongenburger #if defined(LIBC_SCCS) && !defined(lint)
35*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: strnlen.c,v 1.2 2014/01/09 11:25:11 apb Exp $");
366b882151SKees Jongenburger #endif /* LIBC_SCCS and not lint */
376b882151SKees Jongenburger /* FreeBSD: src/lib/libc/string/strnlen.c,v 1.1 2009/02/28 06:00:58 das Exp */
386b882151SKees Jongenburger
39f14fb602SLionel Sambuc #if !defined(_KERNEL) && !defined(_STANDALONE)
406b882151SKees Jongenburger #include <string.h>
41f14fb602SLionel Sambuc #else
42f14fb602SLionel Sambuc #include <lib/libkern/libkern.h>
43f14fb602SLionel Sambuc #endif
446b882151SKees Jongenburger
45*0a6a1f1dSLionel Sambuc #if !HAVE_STRNLEN
466b882151SKees Jongenburger size_t
strnlen(const char * s,size_t maxlen)476b882151SKees Jongenburger strnlen(const char *s, size_t maxlen)
486b882151SKees Jongenburger {
496b882151SKees Jongenburger size_t len;
506b882151SKees Jongenburger
516b882151SKees Jongenburger for (len = 0; len < maxlen; len++, s++) {
526b882151SKees Jongenburger if (!*s)
536b882151SKees Jongenburger break;
546b882151SKees Jongenburger }
556b882151SKees Jongenburger return (len);
566b882151SKees Jongenburger }
57*0a6a1f1dSLionel Sambuc #endif /* !HAVE_STRNLEN */
58