1 //! locale implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/locale.h.html 2 3 use core::ptr; 4 5 6 7 const EMPTY_PTR: *const ::c_char = "\0" as *const _ as *const ::c_char; 8 // Can't use &str because of the mutability 9 static mut C_LOCALE: [::c_char; 2] = [b'C' as ::c_char, 0]; 10 11 #[repr(C)] 12 pub struct lconv { 13 currency_symbol: *const ::c_char, 14 decimal_point: *const ::c_char, 15 frac_digits: ::c_char, 16 grouping: *const ::c_char, 17 int_curr_symbol: *const ::c_char, 18 int_frac_digits: ::c_char, 19 mon_decimal_point: *const ::c_char, 20 mon_grouping: *const ::c_char, 21 mon_thousands_sep: *const ::c_char, 22 negative_sign: *const ::c_char, 23 n_cs_precedes: ::c_char, 24 n_sep_by_space: ::c_char, 25 n_sign_posn: ::c_char, 26 positive_sign: *const ::c_char, 27 p_cs_precedes: ::c_char, 28 p_sep_by_space: ::c_char, 29 p_sign_posn: ::c_char, 30 thousands_sep: *const ::c_char, 31 } 32 unsafe impl Sync for lconv {} 33 34 // Mutable because POSIX demands a mutable pointer, even though it warns 35 // against mutating it 36 static mut CURRENT_LOCALE: lconv = lconv { 37 currency_symbol: EMPTY_PTR, 38 decimal_point: ".\0" as *const _ as *const ::c_char, 39 frac_digits: ::c_char::max_value(), 40 grouping: EMPTY_PTR, 41 int_curr_symbol: EMPTY_PTR, 42 int_frac_digits: ::c_char::max_value(), 43 mon_decimal_point: EMPTY_PTR, 44 mon_grouping: EMPTY_PTR, 45 mon_thousands_sep: EMPTY_PTR, 46 negative_sign: EMPTY_PTR, 47 n_cs_precedes: ::c_char::max_value(), 48 n_sep_by_space: ::c_char::max_value(), 49 n_sign_posn: ::c_char::max_value(), 50 positive_sign: EMPTY_PTR, 51 p_cs_precedes: ::c_char::max_value(), 52 p_sep_by_space: ::c_char::max_value(), 53 p_sign_posn: ::c_char::max_value(), 54 thousands_sep: EMPTY_PTR, 55 }; 56 57 #[no_mangle] 58 pub unsafe extern "C" fn localeconv() -> *mut lconv { 59 &mut CURRENT_LOCALE as *mut _ 60 } 61 62 #[no_mangle] 63 pub unsafe extern "C" fn setlocale(_option: ::c_int, val: *const ::c_char) -> *mut ::c_char { 64 if val.is_null() { 65 return C_LOCALE.as_mut_ptr() as *mut ::c_char; 66 } 67 // TODO actually implement 68 ptr::null_mut() 69 } 70