Files
Tristan Partin a01a126fd0 wrap: fix locale fallback logic when LANG is unset
`set_stdio_encoding()` assumed `setlocale(LC_ALL, "")` returns NULL when
`LANG`/`LC_ALL` are unset, and only fell back to "C.UTF-8"/"UTF-8" in
that case. In practice, POSIX libc implementations return the non-NULL
string "C" in that situation, so the fallback was never taken. "C"'s
codeset is US-ASCII, so wrap exited with:

	error: locale 'C' is not UTF-8

Add `locale_supports_utf8()` to check the actual codeset instead of just
checking for NULL, and use it to gate every step of the fallback chain,
including the final result. This also fixes the same failure when `LANG`
names a real but non-UTF-8 locale (e.g. `LANG=en_US.ISO8859-1`), which
previously skipped the fallback entirely instead of trying
"C.UTF-8"/"UTF-8".

Changelog-fixed: Fix wrap filter when `LANG` or `LC_ALL` are
 unset. Previously it would error out.
Signed-off-by: Tristan Partin <tristan@partin.io>
Acked-by: Robin Jarry <robin@jarry.cc>
2026-09-14 22:33:33 +02:00
..
2022-07-11 15:53:23 +02:00
2025-05-12 13:18:25 +02:00