xref: /titanic_51/usr/src/lib/libc/port/locale/mbrtowc.c (revision d8e0a9a12d4d1ec2e9410b384d25d738daf9f240)
14297a3b0SGarrett D'Amore /*
22d08521bSGarrett D'Amore  * Copyright 2013 Garrett D'Amore <garrett@damore.org>
36b5e5868SGarrett D'Amore  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
44297a3b0SGarrett D'Amore  * Copyright (c) 2002-2004 Tim J. Robbins.
54297a3b0SGarrett D'Amore  * All rights reserved.
64297a3b0SGarrett D'Amore  *
74297a3b0SGarrett D'Amore  * Redistribution and use in source and binary forms, with or without
84297a3b0SGarrett D'Amore  * modification, are permitted provided that the following conditions
94297a3b0SGarrett D'Amore  * are met:
104297a3b0SGarrett D'Amore  * 1. Redistributions of source code must retain the above copyright
114297a3b0SGarrett D'Amore  *    notice, this list of conditions and the following disclaimer.
124297a3b0SGarrett D'Amore  * 2. Redistributions in binary form must reproduce the above copyright
134297a3b0SGarrett D'Amore  *    notice, this list of conditions and the following disclaimer in the
144297a3b0SGarrett D'Amore  *    documentation and/or other materials provided with the distribution.
154297a3b0SGarrett D'Amore  *
164297a3b0SGarrett D'Amore  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
174297a3b0SGarrett D'Amore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
184297a3b0SGarrett D'Amore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
194297a3b0SGarrett D'Amore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
204297a3b0SGarrett D'Amore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
214297a3b0SGarrett D'Amore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
224297a3b0SGarrett D'Amore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
234297a3b0SGarrett D'Amore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
244297a3b0SGarrett D'Amore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
254297a3b0SGarrett D'Amore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264297a3b0SGarrett D'Amore  * SUCH DAMAGE.
274297a3b0SGarrett D'Amore  */
284297a3b0SGarrett D'Amore 
294297a3b0SGarrett D'Amore #include "lint.h"
304297a3b0SGarrett D'Amore #include <wchar.h>
314297a3b0SGarrett D'Amore #include "mblocal.h"
322d08521bSGarrett D'Amore #include "localeimpl.h"
332d08521bSGarrett D'Amore #include "lctype.h"
344297a3b0SGarrett D'Amore 
354297a3b0SGarrett D'Amore size_t
362d08521bSGarrett D'Amore mbrtowc_l(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
372d08521bSGarrett D'Amore     size_t n, mbstate_t *_RESTRICT_KYWD ps, locale_t loc)
384297a3b0SGarrett D'Amore {
394297a3b0SGarrett D'Amore 	static mbstate_t mbs;
404297a3b0SGarrett D'Amore 
414297a3b0SGarrett D'Amore 	if (ps == NULL)
424297a3b0SGarrett D'Amore 		ps = &mbs;
43*d8e0a9a1SRobert Mustacchi 	return (loc->ctype->lc_mbrtowc(pwc, s, n, ps, B_FALSE));
442d08521bSGarrett D'Amore }
452d08521bSGarrett D'Amore 
462d08521bSGarrett D'Amore size_t
472d08521bSGarrett D'Amore mbrtowc(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
482d08521bSGarrett D'Amore     size_t n, mbstate_t *_RESTRICT_KYWD ps)
492d08521bSGarrett D'Amore {
502d08521bSGarrett D'Amore 	return (mbrtowc_l(pwc, s, n, ps, uselocale(NULL)));
514297a3b0SGarrett D'Amore }
52*d8e0a9a1SRobert Mustacchi 
53*d8e0a9a1SRobert Mustacchi size_t
54*d8e0a9a1SRobert Mustacchi mbrtowc_nz_l(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
55*d8e0a9a1SRobert Mustacchi     size_t n, mbstate_t *_RESTRICT_KYWD ps, locale_t loc)
56*d8e0a9a1SRobert Mustacchi {
57*d8e0a9a1SRobert Mustacchi 	static mbstate_t mbs;
58*d8e0a9a1SRobert Mustacchi 
59*d8e0a9a1SRobert Mustacchi 	if (ps == NULL)
60*d8e0a9a1SRobert Mustacchi 		ps = &mbs;
61*d8e0a9a1SRobert Mustacchi 	return (loc->ctype->lc_mbrtowc(pwc, s, n, ps, B_TRUE));
62*d8e0a9a1SRobert Mustacchi }
63*d8e0a9a1SRobert Mustacchi 
64*d8e0a9a1SRobert Mustacchi size_t
65*d8e0a9a1SRobert Mustacchi mbrtowc_nz(wchar_t *_RESTRICT_KYWD pwc, const char *_RESTRICT_KYWD s,
66*d8e0a9a1SRobert Mustacchi     size_t n, mbstate_t *_RESTRICT_KYWD ps)
67*d8e0a9a1SRobert Mustacchi {
68*d8e0a9a1SRobert Mustacchi 	return (mbrtowc_nz_l(pwc, s, n, ps, uselocale(NULL)));
69*d8e0a9a1SRobert Mustacchi }
70