2 ** Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>. All rights reserved.
3 ** Distributed under the terms of the Haiku License.
10 #include <errno_private.h>
11 #include <LocaleBackend.h>
14 //#define TRACE_WCRTOMB
17 # define TRACE(x) debug_printf x
23 using BPrivate::Libroot::gLocaleBackend
;
27 __wcrtomb(char* s
, wchar_t wc
, mbstate_t* ps
)
30 static mbstate_t internalMbState
;
31 ps
= &internalMbState
;
37 if (gLocaleBackend
== NULL
) {
39 * The POSIX locale is active. Since the POSIX locale only contains
40 * chars 0-127 and those ASCII chars are compatible with the UTF32
41 * values used in wint_t, we can just return the byte.
57 status_t status
= gLocaleBackend
->WcharToMultibyte(s
, wc
, ps
, lengthUsed
);
59 if (status
== B_BAD_INDEX
)
62 if (status
== B_BAD_DATA
) {
63 TRACE(("mbrtowc(): setting errno to EILSEQ\n"));
69 TRACE(("wcrtomb(): setting errno to EINVAL (status: %lx)\n", status
));
79 B_DEFINE_WEAK_ALIAS(__wcrtomb
, wcrtomb
);