xref: /titanic_51/usr/src/lib/libc/port/locale/mbsinit.c (revision 9a4a12bd7ce60cd60eae508b25eb7a8dae765274)
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*9a4a12bdSRobert Mustacchi #include "mblocal.h"
214297a3b0SGarrett D'Amore 
224297a3b0SGarrett D'Amore int
232d08521bSGarrett D'Amore mbsinit_l(const mbstate_t *s, locale_t loc)
244297a3b0SGarrett D'Amore {
25*9a4a12bdSRobert Mustacchi 
26*9a4a12bdSRobert Mustacchi 	/*
27*9a4a12bdSRobert Mustacchi 	 * To implement support for the C11 char16_t conversion functions
28*9a4a12bdSRobert Mustacchi 	 * (mbrtoc16() and c16rtomb()) we opted to leverage all of the existing
29*9a4a12bdSRobert Mustacchi 	 * conversion infrastructure, including the per-locale conversion
30*9a4a12bdSRobert Mustacchi 	 * structures. The char16_t conversion functions tack an extra member in
31*9a4a12bdSRobert Mustacchi 	 * the mbstate_t that occurs after all others have placed their data.
32*9a4a12bdSRobert Mustacchi 	 * Therefore, before we go to the per-locale backend we need to see if
33*9a4a12bdSRobert Mustacchi 	 * there is any outstanding state in the char16_t specific state.
34*9a4a12bdSRobert Mustacchi 	 */
35*9a4a12bdSRobert Mustacchi 	if (s != NULL) {
36*9a4a12bdSRobert Mustacchi 		const _CHAR16State *c16s = (const _CHAR16State *)s;
37*9a4a12bdSRobert Mustacchi 		if (c16s->c16_surrogate != 0) {
38*9a4a12bdSRobert Mustacchi 			return (0);
39*9a4a12bdSRobert Mustacchi 		}
40*9a4a12bdSRobert Mustacchi 	}
41*9a4a12bdSRobert Mustacchi 
422d08521bSGarrett D'Amore 	return (loc->ctype->lc_mbsinit(s));
432d08521bSGarrett D'Amore }
444297a3b0SGarrett D'Amore 
452d08521bSGarrett D'Amore int
462d08521bSGarrett D'Amore mbsinit(const mbstate_t *s)
472d08521bSGarrett D'Amore {
482d08521bSGarrett D'Amore 	return (mbsinit_l(s, uselocale(NULL)));
494297a3b0SGarrett D'Amore }
50