X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Fwidechar%2Fcharable.c;h=104f59dd8560e37bf2eecc798d83ed4a5a8ded57;hp=7e7dfe675b22b30854db928c38ea43a0318efd4f;hb=78b0123661ebab93d5bd5345b89e6e76d6560ec0;hpb=a8987e73ec254703634802b4f7ee30d3a485524d diff --git a/ncurses/widechar/charable.c b/ncurses/widechar/charable.c index 7e7dfe67..104f59dd 100644 --- a/ncurses/widechar/charable.c +++ b/ncurses/widechar/charable.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2003 Free Software Foundation, Inc. * + * Copyright (c) 2003-2008,2018 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -32,13 +32,13 @@ #include -MODULE_ID("$Id: charable.c,v 1.2 2003/07/05 18:04:08 tom Exp $") +MODULE_ID("$Id: charable.c,v 1.7 2018/06/30 20:46:25 tom Exp $") NCURSES_EXPORT(bool) _nc_is_charable(wchar_t ch) { bool result; #if HAVE_WCTOB - result = (wctob(ch) == ch); + result = (wctob((wint_t) ch) == (int) ch); #else result = (_nc_to_char(ch) >= 0); #endif @@ -57,6 +57,8 @@ NCURSES_EXPORT(int) _nc_to_char(wint_t ch) result = UChar(temp[0]); else result = -1; +#else +#error expected either wctob/wctomb #endif return result; } @@ -67,11 +69,16 @@ NCURSES_EXPORT(wint_t) _nc_to_widechar(int ch) #if HAVE_BTOWC result = btowc(ch); #elif HAVE_MBTOWC + wchar_t convert; char temp[2]; temp[0] = ch; temp[1] = '\0'; - if (mbtowc((wchar_t *) (&result), temp, 1) != 1) + if (mbtowc(&convert, temp, 1) >= 0) + result = convert; + else result = WEOF; +#else +#error expected either btowc/mbtowc #endif return result; }