Thanks for the further patch. Some comments:
+ if (!mbsinit (&mbs))
+ memset (&mbs, 0, sizeof mbs);
Why bother with mbsinit? Just do the memset, or better yet declare and
initialize mbs here.
+ mbclen_guess[i] = mbrlen ((const char *) &i, 1, &mbs);
This assumes a little-endian machine, which is not portable. Please use
something like this instead:
for (i = CHAR_MIN; i <= CHAR_MAX; i++)
{
char c = i;
unsigned char uc = i;
mbstate_t mbs = { 0 };
mbclen_guess[uc] = mbrlen (&c, 1, &mbs);
}
Here I'm using a style that avoids casts, as casts in general can be
dangerous.
A minor question about naming: in what sense is mbclen_guess a guess?
It doesn't seem to be guessing anything. Perhaps rename it to mbclen_cache?