+MODULE_ID("$Id: lib_unget_wch.c,v 1.16 2016/05/28 23:36:34 tom Exp $")
+
+/*
+ * Wrapper for wcrtomb() which obtains the length needed for the given
+ * wide-character 'source'.
+ */
+NCURSES_EXPORT(size_t)
+_nc_wcrtomb(char *target, wchar_t source, mbstate_t * state)
+{
+ int result;
+
+ if (target == 0) {
+ wchar_t temp[2];
+ const wchar_t *tempp = temp;
+ temp[0] = source;
+ temp[1] = 0;
+ result = (int) wcsrtombs(NULL, &tempp, (size_t) 0, state);
+ } else {
+ result = (int) wcrtomb(target, source, state);
+ }
+ if (!isEILSEQ(result) && (result == 0))
+ result = 1;
+ return (size_t) result;
+}