Skip to content
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

setlocale: If locale setting fails, try using C.UTF-8 as fallback #1713

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions dnf5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,11 @@ static void print_new_leaves(Context & context) {
}

static void set_locale() {
auto * locale = setlocale(LC_ALL, "");
if (locale) {
if (setlocale(LC_ALL, "")) {
return;
}
if (setlocale(LC_ALL, "C.UTF-8")) {
std::cerr << "Failed to set locale, defaulting to \"C.UTF-8\"" << std::endl;
return;
}
std::cerr << "Failed to set locale, defaulting to \"C\"" << std::endl;
Expand Down
15 changes: 14 additions & 1 deletion dnf5daemon-client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,23 @@ static void add_commands(Context & context) {

} // namespace dnfdaemon::client


static void set_locale() {
if (setlocale(LC_ALL, "")) {
return;
}
if (setlocale(LC_ALL, "C.UTF-8")) {
std::cerr << "Failed to set locale, defaulting to \"C.UTF-8\"" << std::endl;
return;
}
std::cerr << "Failed to set locale, defaulting to \"C\"" << std::endl;
}


int main(int argc, char * argv[]) {
std::unique_ptr<sdbus::IConnection> connection;

setlocale(LC_ALL, "");
set_locale();

dnfdaemon::client::Context context;

Expand Down
Loading