Skip to content

Commit

Permalink
setlocale: If locale setting fails, try using C.UTF-8 as fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
jrohel committed Sep 19, 2024
1 parent 117bc3e commit 494d88f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
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

0 comments on commit 494d88f

Please sign in to comment.