Skip to content
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: 7 additions & 0 deletions src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1752,10 +1752,17 @@ fn default_merge_batch_size() -> usize {
}
}

#[cfg(not(unix))]
fn locale_failed_to_set() -> bool {
matches!(env::var("LC_ALL").ok().as_deref(), Some("missing"))
}

#[cfg(unix)]
fn locale_failed_to_set() -> bool {
use nix::libc;
unsafe { libc::setlocale(libc::LC_COLLATE, c"".as_ptr()).is_null() }
}

fn key_zero_width(selector: &FieldSelector) -> bool {
let Some(to) = &selector.to else {
return false;
Expand Down
15 changes: 15 additions & 0 deletions tests/by-util/test_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2733,6 +2733,21 @@ fn test_locale_utf8_sort_debug_message() {
.stderr_contains("text ordering performed using ‘en_US.UTF-8’ sorting rules");
}

#[test]
#[cfg(unix)]
fn test_failed_to_set_locale_debug_message() {
let result = new_ucmd!()
.env("LC_ALL", "not-valid-locale")
.arg("--debug")
.pipe_in("a\nA\nb\nB\n")
.succeeds();

result.stderr_contains("text ordering performed using simple byte comparison");

#[cfg(all(target_os = "linux", target_env = "gnu"))]
result.stderr_contains("failed to set locale");
}

#[test]
fn test_locale_utf8_with_key_field() {
// Regression test for issue #10909
Expand Down
Loading