xref: /titanic_50/usr/src/lib/libc/port/locale/mbsinit.c (revision 8cfa78e6de0de88f6a15cd29ee5f6a8a1bfe7c20)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2013 Garrett D'Amore <garrett@damore.org>
14  */
15 
16 #include "lint.h"
17 #include <locale.h>
18 #include "localeimpl.h"
19 #include "lctype.h"
20 #include "mblocal.h"
21 
22 int
23 mbsinit_l(const mbstate_t *s, locale_t loc)
24 {
25 
26 	/*
27 	 * To implement support for the C11 char16_t conversion functions
28 	 * (mbrtoc16() and c16rtomb()) we opted to leverage all of the existing
29 	 * conversion infrastructure, including the per-locale conversion
30 	 * structures. The char16_t conversion functions tack an extra member in
31 	 * the mbstate_t that occurs after all others have placed their data.
32 	 * Therefore, before we go to the per-locale backend we need to see if
33 	 * there is any outstanding state in the char16_t specific state.
34 	 */
35 	if (s != NULL) {
36 		const _CHAR16State *c16s = (const _CHAR16State *)s;
37 		if (c16s->c16_surrogate != 0) {
38 			return (0);
39 		}
40 	}
41 
42 	return (loc->ctype->lc_mbsinit(s));
43 }
44 
45 int
46 mbsinit(const mbstate_t *s)
47 {
48 	return (mbsinit_l(s, uselocale(NULL)));
49 }
50