1*e9f3be3aSjca /* $OpenBSD: wcsnlen.c,v 1.1 2024/07/14 09:51:18 jca Exp $ */
2*e9f3be3aSjca /* $NetBSD: wcslen.c,v 1.2 2001/01/03 14:29:36 lukem Exp $ */
3*e9f3be3aSjca
4*e9f3be3aSjca /*-
5*e9f3be3aSjca * Copyright (c)1999 Citrus Project,
6*e9f3be3aSjca * All rights reserved.
7*e9f3be3aSjca *
8*e9f3be3aSjca * Redistribution and use in source and binary forms, with or without
9*e9f3be3aSjca * modification, are permitted provided that the following conditions
10*e9f3be3aSjca * are met:
11*e9f3be3aSjca * 1. Redistributions of source code must retain the above copyright
12*e9f3be3aSjca * notice, this list of conditions and the following disclaimer.
13*e9f3be3aSjca * 2. Redistributions in binary form must reproduce the above copyright
14*e9f3be3aSjca * notice, this list of conditions and the following disclaimer in the
15*e9f3be3aSjca * documentation and/or other materials provided with the distribution.
16*e9f3be3aSjca *
17*e9f3be3aSjca * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18*e9f3be3aSjca * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19*e9f3be3aSjca * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20*e9f3be3aSjca * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21*e9f3be3aSjca * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*e9f3be3aSjca * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23*e9f3be3aSjca * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24*e9f3be3aSjca * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25*e9f3be3aSjca * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26*e9f3be3aSjca * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27*e9f3be3aSjca * SUCH DAMAGE.
28*e9f3be3aSjca *
29*e9f3be3aSjca * citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
30*e9f3be3aSjca */
31*e9f3be3aSjca
32*e9f3be3aSjca #include <wchar.h>
33*e9f3be3aSjca
34*e9f3be3aSjca size_t
wcsnlen(const wchar_t * s,size_t maxlen)35*e9f3be3aSjca wcsnlen(const wchar_t *s, size_t maxlen)
36*e9f3be3aSjca {
37*e9f3be3aSjca const wchar_t *p;
38*e9f3be3aSjca
39*e9f3be3aSjca p = s;
40*e9f3be3aSjca while (maxlen-- && *p)
41*e9f3be3aSjca p++;
42*e9f3be3aSjca
43*e9f3be3aSjca return p - s;
44*e9f3be3aSjca }
45*e9f3be3aSjca
46