diff --git a/src/locale/src/lib.rs b/src/locale/src/lib.rs index 17e438e615fbf88835cb4599a8070d864f20b2a2..f71380b3533c2a3a388d891ed6cbb1a35ce0d842 100644 --- a/src/locale/src/lib.rs +++ b/src/locale/src/lib.rs @@ -9,6 +9,7 @@ use core::ptr; use platform::types::*; const EMPTY_PTR: *const c_char = "\0" as *const _ as *const c_char; +static mut C_LOCALE: [c_char; 2] = [b'C' as c_char, 0]; #[repr(C)] #[no_mangle] @@ -61,10 +62,11 @@ pub extern "C" fn localeconv() -> *const lconv { } #[no_mangle] -pub extern "C" fn setlocale(_option: c_int, val: *const c_char) -> *const c_char { +pub unsafe extern "C" fn setlocale(_option: c_int, val: *const c_char) -> *mut c_char { if val.is_null() { - return "C\0".as_ptr() as *const c_char; + // Can't use string`` + return C_LOCALE.as_mut_ptr() as *mut c_char; } // TODO actually implement - ptr::null() + ptr::null_mut() } diff --git a/tests/locale.c b/tests/locale.c index eba2ecede1d7ea8204ec9adae781ab27e7da5b8e..9358bc5554319b7dbfdc3ef62bfdb90a519c008f 100644 --- a/tests/locale.c +++ b/tests/locale.c @@ -4,7 +4,7 @@ int main() { // TODO: Implement locale properly and test it here - const char* val = setlocale(LC_ALL, NULL); + char* val = setlocale(LC_ALL, NULL); if (strcmp(val, "C") == 0) { puts("success!"); } else {