Thanks very much. I read through that patch and think we can come up with a simpler cache that need not store lengths, but reserves WEOF to represent an incomplete multibyte character. This approach simplifies the code and avoids some glitches when mbrtowc returns special values not in the range 1..N. How about the attached patch instead?