1 /* $MirOS: src/lib/libc/i18n/mblen.c,v 1.4 2007/02/02 21:06:21 tg Exp $ */
2 
3 /*-
4  * Copyright (c) 2006
5  *	Thorsten Glaser <tg@mirbsd.de>
6  *
7  * Provided that these terms and disclaimer and all copyright notices
8  * are retained or reproduced in an accompanying document, permission
9  * is granted to deal in this work without restriction, including un-
10  * limited rights to use, publicly perform, distribute, sell, modify,
11  * merge, give away, or sublicence.
12  *
13  * Advertising materials mentioning features or use of this work must
14  * display the following acknowledgement:
15  *	This product includes material provided by Thorsten Glaser.
16  *
17  * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
18  * the utmost extent permitted by applicable law, neither express nor
19  * implied; without malicious intent or gross negligence. In no event
20  * may a licensor, author or contributor be held liable for indirect,
21  * direct, other damage, loss, or other issues arising in any way out
22  * of dealing in the work, even if advised of the possibility of such
23  * damage or existence of a defect, except proven that it results out
24  * of said person's immediate fault when using the work as intended.
25  */
26 
27 #include <wchar.h>
28 
29 __RCSID("$MirOS: src/lib/libc/i18n/mblen.c,v 1.4 2007/02/02 21:06:21 tg Exp $");
30 
31 #undef mblen
32 int
mblen(const char * s,size_t n)33 mblen(const char *s, size_t n)
34 {
35 	mbstate_t state = { 0, 0 };
36 	int rv;
37 
38 	return (((rv = mbrtowc(NULL, s, n, &state)) < 0) ? -1 : rv);
39 }
40