Skip to content

console: fix getwchar failing when LC_ALL undefined #3688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion common/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,16 @@ namespace console {
}
}

setlocale(LC_ALL, "");
auto locale = setlocale(LC_ALL, "");
auto lang = getenv("LANG");

if (locale == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a reasonable fix to me. Since it's not often needed, it may be better to defer the retrieval of the "LANG" environment variable until it's needed, but it's good as is.

Suggested change
auto lang = getenv("LANG");
if (locale == nullptr) {
if (locale == nullptr) {
auto lang = getenv("LANG");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one more case, default debian 12 minimal image, and probably more default images for vm/lxc/docker can have a non utf LC_ALL and non utf lang, so just one more commit.

if (lang != nullptr) {
setlocale(LC_ALL, lang);
} else{
setlocale(LC_ALL, "C.UTF-8");
}
}
#endif
}

Expand Down