1 /* Convert wide character to multibyte character.
2 Copyright (C) 2008-2024 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
28 wcrtomb (char *s
, wchar_t wc
, mbstate_t *ps
)
31 /* This implementation of wcrtomb supports only stateless encodings.
32 ps must be in an initial state. */
33 if (ps
!= NULL
&& !mbsinit (ps
))
39 #if !HAVE_WCRTOMB /* IRIX 6.5 */ \
40 || WCRTOMB_RETVAL_BUG /* Solaris 11.3, MSVC */ \
41 || WCRTOMB_C_LOCALE_BUG /* Android */
43 /* We know the NUL wide character corresponds to the NUL character. */
49 # if WCRTOMB_C_LOCALE_BUG /* Android */
50 /* Implement consistently with mbrtowc(): through a 1:1 correspondence,
52 if (wc
>= 0 && wc
<= 0xff)
54 *s
= (unsigned char) wc
;
63 return wcrtomb (s
, wc
, ps
);
66 /* Fallback for platforms that don't have wcrtomb().
67 Implement on top of wctomb().
68 This code is not multithread-safe. */
69 int ret
= wctomb (s
, wc
);