1 /* Convert multibyte character to wide character.
2 Copyright (C) 1999-2002, 2005-2020 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2008.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
23 #if GNULIB_defined_mbstate_t
24 /* Implement mbrtowc() on top of mbtowc() for the non-UTF-8 locales
25 and directly for the UTF-8 locales. */
31 # if defined _WIN32 && !defined __CYGWIN__
33 # define WIN32_LEAN_AND_MEAN /* avoid including junk */
36 # elif HAVE_PTHREAD_API
39 # if HAVE_THREADS_H && HAVE_WEAK_SYMBOLS
41 # pragma weak thrd_exit
42 # define c11_threads_in_use() (thrd_exit != NULL)
44 # define c11_threads_in_use() 0
54 # include "lc-charset-dispatch.h"
55 # include "mbtowc-lock.h"
59 # define FALLTHROUGH ((void) 0)
61 # define FALLTHROUGH __attribute__ ((__fallthrough__))
65 verify (sizeof (mbstate_t) >= 4);
66 static char internal_state
[4];
69 mbrtowc (wchar_t *pwc
, const char *s
, size_t n
, mbstate_t *ps
)
71 # define FITS_IN_CHAR_TYPE(wc) ((wc) <= WCHAR_MAX)
72 # include "mbrtowc-impl.h"
76 /* Override the system's mbrtowc() function. */
78 # if MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ
79 # include "hard-locale.h"
86 rpl_mbrtowc (wchar_t *pwc
, const char *s
, size_t n
, mbstate_t *ps
)
91 # if MBRTOWC_NULL_ARG2_BUG || MBRTOWC_RETVAL_BUG || MBRTOWC_EMPTY_INPUT_BUG
100 # if MBRTOWC_EMPTY_INPUT_BUG
108 # if MBRTOWC_RETVAL_BUG
110 static mbstate_t internal_state
;
112 /* Override mbrtowc's internal state. We cannot call mbsinit() on the
113 hidden internal state, but we can call it on our variable. */
115 ps
= &internal_state
;
119 /* Parse the rest of the multibyte character byte for byte. */
121 for (; n
> 0; s
++, n
--)
123 ret
= mbrtowc (&wc
, s
, 1, ps
);
125 if (ret
== (size_t)(-1))
128 if (ret
!= (size_t)(-2))
130 /* The multibyte character has been completed. */
132 return (wc
== 0 ? 0 : count
);
140 # if MBRTOWC_STORES_INCOMPLETE_BUG
141 ret
= mbrtowc (&wc
, s
, n
, ps
);
142 if (ret
< (size_t) -2 && pwc
!= NULL
)
145 ret
= mbrtowc (pwc
, s
, n
, ps
);
148 # if MBRTOWC_NUL_RETVAL_BUG
149 if (ret
< (size_t) -2 && !*pwc
)
153 # if MBRTOWC_IN_C_LOCALE_MAYBE_EILSEQ
154 if ((size_t) -2 <= ret
&& n
!= 0 && ! hard_locale (LC_CTYPE
))
156 unsigned char uc
= *s
;
This page took 0.032665 seconds and 4 git commands to generate.