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