In general, I think the problem is that we might be dealing with a Unix-style locale string, in which the encoding name might be quite a few other things besides "utf8". But actually your patch works for that too, since what's going to happen next is we'll search the encoding_match_list[] for a match. I do suggest being a bit more paranoid about what's a codepage number though, as attached. (Untested, since I lack a Windows environment, but it's pretty straightforward code.)
It works for the issue just fine, and more comments make a better a patch, so no objections from me.