setlocale succeeds: $ LC_ALL=lv_LV locale LANG= LC_CTYPE="lv_LV" LC_NUMERIC="lv_LV" LC_TIME="lv_LV" LC_COLLATE="lv_LV" LC_MONETARY="lv_LV" LC_MESSAGES="lv_LV" LC_PAPER="lv_LV" LC_NAME="lv_LV" LC_ADDRESS="lv_LV" LC_TELEPHONE="lv_LV" LC_MEASUREMENT="lv_LV" LC_IDENTIFICATION="lv_LV" LC_ALL=lv_LV The locale uses a somewhat unusual charset: # LC_ALL=lv_LV locale -k charmap charmap="ISO-8859-13" But the charset is not installed: # iconv -f UTF-8 -t ISO-8859-13 iconv: failed to start conversion processing So mbstowcs fails to work. Pointed out by Victor Stinner here: https://bugzilla.redhat.com/show_bug.cgi?id=1973663#c11
I agree setlocale should fail in this case.
Calling locale that way does not actually call setlocale(). I've got a test with a patch which does; sending soon.
It may be prudent to turn ISO-8859-1 and ISO-8859-15 into internal converts, too, so that we don't encounter additional overhead due to early converter loading for these (somewhat common) character sets.