mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
Merge pull request #588 from mitchellh/corrupt-lang
os: we need to copy the old lang pointer before we unsetenv
This commit is contained in:
@ -26,7 +26,7 @@ pub fn ensureLocale() void {
|
|||||||
|
|
||||||
// Set the locale to whatever is set in env vars.
|
// Set the locale to whatever is set in env vars.
|
||||||
if (setlocale(LC_ALL, "")) |v| {
|
if (setlocale(LC_ALL, "")) |v| {
|
||||||
log.debug("setlocale result={s}", .{v});
|
log.info("setlocale from env result={s}", .{v});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,19 +34,23 @@ pub fn ensureLocale() void {
|
|||||||
// invalid. Try to set it without the LANG var set to use the system
|
// invalid. Try to set it without the LANG var set to use the system
|
||||||
// default.
|
// default.
|
||||||
if (std.os.getenv("LANG")) |old_lang| {
|
if (std.os.getenv("LANG")) |old_lang| {
|
||||||
|
if (old_lang.len > 0) {
|
||||||
|
// We don't need to do both of these things but we do them
|
||||||
|
// both to be sure that lang is either empty or unset completely.
|
||||||
|
_ = setenv("LANG", "", 1);
|
||||||
_ = unsetenv("LANG");
|
_ = unsetenv("LANG");
|
||||||
defer _ = setenv("LANG", old_lang.ptr, 1);
|
|
||||||
|
|
||||||
if (setlocale(LC_ALL, "")) |v| {
|
if (setlocale(LC_ALL, "")) |v| {
|
||||||
log.debug("setlocale result={s}", .{v});
|
log.info("setlocale after unset lang result={s}", .{v});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Failure again... fallback to en_US.UTF-8
|
// Failure again... fallback to en_US.UTF-8
|
||||||
log.warn("setlocale failed with LANG and system default. Falling back to en_US.UTF-8", .{});
|
log.warn("setlocale failed with LANG and system default. Falling back to en_US.UTF-8", .{});
|
||||||
if (setlocale(LC_ALL, "en_US.UTF-8")) |v| {
|
if (setlocale(LC_ALL, "en_US.UTF-8")) |v| {
|
||||||
log.debug("setlocale result={s}", .{v});
|
log.info("setlocale default result={s}", .{v});
|
||||||
return;
|
return;
|
||||||
} else log.err("setlocale failed even with the fallback, uncertain results", .{});
|
} else log.err("setlocale failed even with the fallback, uncertain results", .{});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user