diff --git a/src/header/arpa_inet/mod.rs b/src/header/arpa_inet/mod.rs index efd0ad39a7..69df751967 100644 --- a/src/header/arpa_inet/mod.rs +++ b/src/header/arpa_inet/mod.rs @@ -118,16 +118,18 @@ pub unsafe extern "C" fn inet_network(cp: *const c_char) -> in_addr_t { /// Specifications Issue 8. #[deprecated] #[unsafe(no_mangle)] -pub unsafe extern "C" fn inet_ntoa(r#in: in_addr) -> *const c_char { +pub unsafe extern "C" fn inet_ntoa(r#in: in_addr) -> *mut c_char { static NTOA_ADDR: RawCell<[c_char; 16]> = RawCell::new([0; 16]); unsafe { - inet_ntop( + let ptr = inet_ntop( AF_INET, &r#in as *const in_addr as *const c_void, NTOA_ADDR.unsafe_mut().as_mut_ptr(), NTOA_ADDR.unsafe_ref().len() as socklen_t, - ) + ); + // Mutable pointer is required, inet_ntop returns destination as const pointer + ptr as *mut c_char } } diff --git a/src/header/langinfo/mod.rs b/src/header/langinfo/mod.rs index 6094b0f5e3..0a9c265b73 100644 --- a/src/header/langinfo/mod.rs +++ b/src/header/langinfo/mod.rs @@ -139,13 +139,16 @@ pub const CRNCYSTR: nl_item = 56; /// # Safety /// - Caller must ensure `item` is a valid `nl_item` index. /// - Returns a pointer to a null-terminated string, or an empty string if the item is invalid. +/// - Compatibility requires mutable pointer to be returned, but it should not be mutated! #[unsafe(no_mangle)] -pub unsafe extern "C" fn nl_langinfo(item: nl_item) -> *const c_char { +pub unsafe extern "C" fn nl_langinfo(item: nl_item) -> *mut c_char { // Validate the item and perform the lookup - if (item as usize) < STRING_TABLE.len() { + let ptr = if (item as usize) < STRING_TABLE.len() { STRING_TABLE[item as usize].as_ptr() as *const c_char } else { // Return a pointer to an empty string if the item is invalid b"\0".as_ptr() as *const c_char - } + }; + // Mutable pointer is required (unsafe!) + ptr as *mut c_char } diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 2d183ba78d..d82228bcd9 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -543,7 +543,7 @@ pub unsafe extern "C" fn timelocal(tm: *mut tm) -> time_t { #[unsafe(no_mangle)] pub unsafe extern "C" fn timer_create( clock_id: clockid_t, - evp: *const sigevent, + evp: *mut sigevent, timerid: *mut timer_t, ) -> c_int { if evp.is_null() || timerid.is_null() { diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 28acfb6efc..590546ddbd 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -835,7 +835,7 @@ pub unsafe extern "C" fn pwrite( /// See . #[unsafe(no_mangle)] -pub unsafe extern "C" fn read(fildes: c_int, buf: *const c_void, nbyte: size_t) -> ssize_t { +pub unsafe extern "C" fn read(fildes: c_int, buf: *mut c_void, nbyte: size_t) -> ssize_t { let buf = unsafe { slice::from_raw_parts_mut(buf as *mut u8, nbyte as usize) }; trace_expr!( Sys::read(fildes, buf)