Skip to content

setlocale and var_os interaction. #22793

Description

@dpc

In my ncurses program if I have two pieces of code:

1:

          if env::var_os("ESCDELAY").is_none() {} 

2:

         unsafe {                                                                                                                                                      
              let _ = locale::setlocale(locale::LC_ALL, b"en_US.UTF-8".as_ptr() as *const i8);                                                                          
          }  

If 2 is before 1, then unicode in my program breaks. If 1 is before 2 everything is fine.

The bindings to setlocale that I use are:

  mod locale {
      use libc::{c_int, c_char};                                                                                                                                        
      pub const LC_ALL: c_int = 6; 
      extern "C" {
           pub fn setlocale(category: c_int, locale: *const c_char) -> *mut c_char;
      }
}

My guess is that std::env is not expecting setlocale changing the underlying environment or something like that. I'm not sure if it's OK, and should it be documented, but decided to let you know, as it was really confusing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions