1 /* @(#)wcsnlen.c	1.3 10/05/07 Copyright 2010 J. Schilling */
2 /*
3  *	wcsnlen() to be used if missing in libc
4  *
5  *	Copyright (c) 2010 J. Schilling
6  */
7 /*
8  * The contents of this file are subject to the terms of the
9  * Common Development and Distribution License, Version 1.0 only
10  * (the "License").  You may not use this file except in compliance
11  * with the License.
12  *
13  * See the file CDDL.Schily.txt in this distribution for details.
14  * A copy of the CDDL is also available via the Internet at
15  * http://www.opensource.org/licenses/cddl1.txt
16  *
17  * When distributing Covered Code, include this CDDL HEADER in each
18  * file and include the License file CDDL.Schily.txt from this distribution.
19  */
20 
21 #include <schily/standard.h>
22 #include <schily/unistd.h>
23 #include <schily/wchar.h>
24 #include <schily/schily.h>
25 
26 #ifndef	HAVE_WCSNLEN
27 
28 EXPORT size_t
wcsnlen(s,len)29 wcsnlen(s, len)
30 	register const wchar_t	*s;
31 	register size_t		len;
32 {
33 	register const wchar_t	*rs = s;
34 
35 	if (len == 0)
36 		return (0);
37 
38 	while (*rs++ != '\0' && --len > 0)
39 			;
40 	if (len == 0)
41 		return (rs - s);
42 	return (--rs - s);
43 }
44 
45 #endif
46