Fix incompatible functions

This commit is contained in:
Jeremy Soller
2025-12-19 12:55:43 -07:00
parent 84c3ba910c
commit 3765148270
4 changed files with 13 additions and 8 deletions
+5 -3
View File
@@ -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
}
}
+6 -3
View File
@@ -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
}
+1 -1
View File
@@ -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() {
+1 -1
View File
@@ -835,7 +835,7 @@ pub unsafe extern "C" fn pwrite(
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/read.html>.
#[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)