Koka / gettext-rs

GNU Gettext FFI binding for Rust
51 stars 25 forks source link

`setlocale` errors on Windows #107

Open ajtribick opened 12 months ago

ajtribick commented 12 months ago

The following fails with STATUS_STACK_BUFFER_OVERRUN on Windows:

use gettextrs::{setlocale, LocaleCategory};

fn main() {
    setlocale(LocaleCategory::LcAll, "");
}

The reason is that the definition of LocaleCategory assumes that the values for the enum members are the same as on (some flavours of) Linux, i.e. that LC_ALL is 6. On Windows, LC_ALL is 0 and 6 is an invalid value for the first parameter, hence the failure.

One potential way to fix this would be to take a dependency on libc and get the constants from there (this would also allow for removing the setlocale definition from gettext-sys), e.g.

pub enum LocaleCategory {
    LcCType = libc::LC_CTYPE as isize,
    LcNumeric = libc::LC_NUMERIC as isize,
    // etc.
}

This would still need to take into account the fact that some of these constants (e.g. LC_MESSAGES) do not exist on non-POSIX systems.