]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/widechar/charable.c
ncurses 5.7 - patch 20091114
[ncurses.git] / ncurses / widechar / charable.c
index 7e7dfe675b22b30854db928c38ea43a0318efd4f..91ceb32ff738407ff0bcaf9f1bdd725ede354b7f 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2003 Free Software Foundation, Inc.                        *
+ * Copyright (c) 2003-2005,2008 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            *
 
 #include <curses.priv.h>
 
-MODULE_ID("$Id: charable.c,v 1.2 2003/07/05 18:04:08 tom Exp $")
+MODULE_ID("$Id: charable.c,v 1.5 2008/07/05 20:51:41 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
@@ -67,10 +67,13 @@ 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;
 #endif
     return result;