/* ps appears to be unused */\r
\r
if (s == NULL)\r
- return 0;\r
+ return 1; /* Spec. says this should be 1. */\r
\r
*s = (char) wchar;\r
return 1;\r
)\r
{\r
\r
- /* s may be NULL */\r
+ /*\r
+ If s is NULL just return if MB Characters have state\r
+ dependent encodings.\r
+ */\r
+ if (s == NULL)\r
+ return 0;\r
\r
return (int)wcrtomb(s, wchar, NULL);\r
}\r
if (n != 0) {\r
if (pwcs != NULL) {\r
do {\r
- if ((*pwcs++ = (wchar_t) *(*s)++) == 0)\r
+ if ((*pwcs++ = (wchar_t) *(*s)++) == 0) {\r
+ *s = NULL;\r
break;\r
+ }\r
count++;\r
} while (--n != 0);\r
} else {\r
\r
if (n != 0) {\r
do {\r
- if ((*s++ = (char) *(*pwcs)++) == 0)\r
+ if ((*s++ = (char) *(*pwcs)++) == 0) {\r
+ *pwcs = NULL;\r
break;\r
+ }\r
count++;\r
} while (--n != 0);\r
}\r
int\r
wctob(wint_t c)\r
{\r
- if (c == WEOF || c & ~0xFF)\r
+ /* wctob needs to be consistent with wcrtomb.\r
+ if wcrtomb says that a character is representable in 1 byte,\r
+ which this implementation always says, then wctob needs to\r
+ also represent the character as 1 byte.\r
+ */\r
+ if (c == WEOF) {\r
return EOF;\r
- return (int)c;\r
+ }\r
+ return (int)(c & 0xFF);\r
}\r