assert: Split some of the work into a separate C file.
[libcstd.git] / src / stdlib / mblen.c
bloba5be8b95b911079d08a6964ae8ba9458d5416089
1 /*
2 * mblen: determine the length of a multibyte character.
3 * Copyright (C) 2009 Nick Bowler.
5 * License LGPLv3+: GNU LGPL version 3 or later. See COPYING.LIB for terms.
6 * See <http://www.gnu.org/licenses/lgpl.html> if you did not receive a copy.
7 * This is free software: you are free to change and redistribute it.
8 * There is NO WARRANTY, to the extent permitted by law.
9 */
10 #include <stdlib.h>
11 #include <wchar.h>
12 #include <cstd/locale.h>
14 int (mblen)(const char *s, size_t n)
16 wint_t wc;
17 char *end;
19 wc = __cstd_conv->decode(s, &end, n);
20 if (wc == WEOF)
21 return -1;
22 if (wc == 0)
23 return 0;
24 return end - s;