Skip to content

Commit 212ee78

Browse files
tr: skip locale initialisation on Windows
On Windows, setlocale with an empty string selects the user's ANSI code page, so the C library classifies high bytes and five existing tests fail. Windows keeps the previous ASCII only behaviour, as on WASI. Also update fuzz/Cargo.lock, which missed the libc dependency added to uu_tr and failed the locked fetch checks.
1 parent 14a2de8 commit 212ee78

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎fuzz/Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/uu/tr/src/operation.rs‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,20 @@ pub enum Sequence {
219219

220220
/// Initialise the process locale from the environment, so the C library
221221
/// classification functions below see the locale the user asked for. This
222-
/// follows the pattern `dd` already uses for its case tables.
223-
#[cfg(not(target_os = "wasi"))]
222+
/// follows the pattern `dd` already uses for its case tables. Windows is
223+
/// left out on purpose: there setlocale with an empty string selects the
224+
/// user's ANSI code page, which makes the C library classify high bytes
225+
/// and changes long standing ASCII only behaviour, breaking existing
226+
/// tests. Windows therefore keeps the previous behaviour.
227+
#[cfg(not(any(target_os = "wasi", target_os = "windows")))]
224228
fn init_locale() {
225229
// SAFETY: setlocale is called with a valid C string, as in `dd`.
226230
unsafe {
227231
libc::setlocale(libc::LC_CTYPE, c"".as_ptr());
228232
}
229233
}
230234

231-
#[cfg(target_os = "wasi")]
235+
#[cfg(any(target_os = "wasi", target_os = "windows"))]
232236
fn init_locale() {}
233237

234238
/// Whether a high byte belongs to a class in the current locale, using the

0 commit comments

Comments
 (0)