xref: /haiku/src/system/libroot/posix/wchar/mblen.c (revision 372b901dfeada686207d00bbcce456f748bbda12)
1 /*
2 ** Copyright 2011, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
4 */
5 
6 #include <wchar_private.h>
7 
8 
9  int
10 __mblen(const char* s, size_t n)
11  {
12 	static mbstate_t internalMbState;
13 	int rval;
14 
15  	if (s == NULL) {
16 		static const mbstate_t initial;
17 
18 		internalMbState = initial;
19 
20 		return 0;	// we do not support stateful converters
21  	}
22 
23 	rval = __mbrtowc(NULL, s, n, &internalMbState);
24 
25 	if (rval == -1 || rval == -2)
26 		return -1;
27 
28 	return rval;
29  }
30 
31 
32 B_DEFINE_WEAK_ALIAS(__mblen, mblen);
33