1 /****************************************************************************
2 * Copyright (c) 2012,2013 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 #include <curses.priv.h>
33 MODULE_ID("$Id: widechars.c,v 1.5 2013/03/02 18:55:51 tom Exp $")
35 #if defined(__MINGW32__)
37 * MinGW has wide-character functions, but they do not work correctly.
41 _nc_mbtowc(wchar_t *pwc
, const char *s
, size_t n
)
47 if (s
!= 0 && n
!= 0) {
49 * MultiByteToWideChar() can decide to return more than one
50 * wide-character. We want only one. Ignore any trailing null, both
51 * in the initial count and in the conversion.
54 for (try = 1; try <= (int) n
; ++try) {
55 count
= MultiByteToWideChar(CP_UTF8
,
61 TR(TRACE_BITS
, ("...try %d:%d", try, count
));
66 if (count
< 1 || count
> 2) {
70 memset(&actual
, 0, sizeof(actual
));
71 count
= MultiByteToWideChar(CP_UTF8
,
77 TR(TRACE_BITS
, ("\twin32 ->%#x, %#x", actual
[0], actual
[1]));
92 _nc_mblen(const char *s
, size_t n
)
98 if (s
!= 0 && n
!= 0) {
99 count
= _nc_mbtowc(&temp
, s
, n
);
101 int check
= WideCharToMultiByte(CP_UTF8
,
106 0, /* compute length only */
109 TR(TRACE_BITS
, ("\tcheck ->%d\n", check
));
110 if (check
> 0 && (size_t) check
<= n
) {
122 _nc_wctomb(char *s
, wchar_t wc
)
127 check
= WideCharToMultiByte(CP_UTF8
,
132 0, /* compute length only */
136 result
= WideCharToMultiByte(CP_UTF8
,
150 #endif /* __MINGW32__ */
152 #endif /* USE_WIDEC_SUPPORT */