xref: /titanic_50/usr/src/lib/libc/port/locale/mbsinit.c (revision 3fc10f8cbc2fd5dd5cd13044edf9cb68a1ef422b)
14297a3b0SGarrett D'Amore /*
22d08521bSGarrett D'Amore  * This file and its contents are supplied under the terms of the
32d08521bSGarrett D'Amore  * Common Development and Distribution License ("CDDL"), version 1.0.
42d08521bSGarrett D'Amore  * You may only use this file in accordance with the terms of version
52d08521bSGarrett D'Amore  * 1.0 of the CDDL.
64297a3b0SGarrett D'Amore  *
72d08521bSGarrett D'Amore  * A full copy of the text of the CDDL should have accompanied this
82d08521bSGarrett D'Amore  * source.  A copy of the CDDL is also available via the Internet at
92d08521bSGarrett D'Amore  * http://www.illumos.org/license/CDDL.
102d08521bSGarrett D'Amore  */
112d08521bSGarrett D'Amore 
122d08521bSGarrett D'Amore /*
132d08521bSGarrett D'Amore  * Copyright 2013 Garrett D'Amore <garrett@damore.org>
144297a3b0SGarrett D'Amore  */
154297a3b0SGarrett D'Amore 
164297a3b0SGarrett D'Amore #include "lint.h"
172d08521bSGarrett D'Amore #include <locale.h>
182d08521bSGarrett D'Amore #include "localeimpl.h"
192d08521bSGarrett D'Amore #include "lctype.h"
20*3fc10f8cSRobert Mustacchi #include "mblocal.h"
214297a3b0SGarrett D'Amore 
224297a3b0SGarrett D'Amore int
mbsinit_l(const mbstate_t * s,locale_t loc)232d08521bSGarrett D'Amore mbsinit_l(const mbstate_t *s, locale_t loc)
244297a3b0SGarrett D'Amore {
25*3fc10f8cSRobert Mustacchi 
26*3fc10f8cSRobert Mustacchi 	/*
27*3fc10f8cSRobert Mustacchi 	 * To implement support for the C11 char16_t conversion functions
28*3fc10f8cSRobert Mustacchi 	 * (mbrtoc16() and c16rtomb()) we opted to leverage all of the existing
29*3fc10f8cSRobert Mustacchi 	 * conversion infrastructure, including the per-locale conversion
30*3fc10f8cSRobert Mustacchi 	 * structures. The char16_t conversion functions tack an extra member in
31*3fc10f8cSRobert Mustacchi 	 * the mbstate_t that occurs after all others have placed their data.
32*3fc10f8cSRobert Mustacchi 	 * Therefore, before we go to the per-locale backend we need to see if
33*3fc10f8cSRobert Mustacchi 	 * there is any outstanding state in the char16_t specific state.
34*3fc10f8cSRobert Mustacchi 	 */
35*3fc10f8cSRobert Mustacchi 	if (s != NULL) {
36*3fc10f8cSRobert Mustacchi 		const _CHAR16State *c16s = (const _CHAR16State *)s;
37*3fc10f8cSRobert Mustacchi 		if (c16s->c16_surrogate != 0) {
38*3fc10f8cSRobert Mustacchi 			return (0);
39*3fc10f8cSRobert Mustacchi 		}
40*3fc10f8cSRobert Mustacchi 	}
41*3fc10f8cSRobert Mustacchi 
422d08521bSGarrett D'Amore 	return (loc->ctype->lc_mbsinit(s));
432d08521bSGarrett D'Amore }
444297a3b0SGarrett D'Amore 
452d08521bSGarrett D'Amore int
mbsinit(const mbstate_t * s)462d08521bSGarrett D'Amore mbsinit(const mbstate_t *s)
472d08521bSGarrett D'Amore {
482d08521bSGarrett D'Amore 	return (mbsinit_l(s, uselocale(NULL)));
494297a3b0SGarrett D'Amore }
50