diff --git a/src/header/_aio/mod.rs b/src/header/_aio/mod.rs index 1baafd0ef9..33a4483817 100644 --- a/src/header/_aio/mod.rs +++ b/src/header/_aio/mod.rs @@ -3,7 +3,7 @@ //! See . use crate::{ - header::{signal::sigevent, time::timespec}, + header::{errno::ENOSYS, signal::sigevent, time::timespec}, platform::types::{c_int, c_void, size_t, ssize_t}, }; @@ -20,13 +20,15 @@ pub struct aiocb { /// See . // #[unsafe(no_mangle)] pub unsafe extern "C" fn aio_read(aiocbp: *mut aiocb) -> c_int { - unimplemented!(); + let _ = aiocbp; + ENOSYS } /// See . // #[unsafe(no_mangle)] pub unsafe extern "C" fn aio_write(aiocbp: *mut aiocb) -> c_int { - unimplemented!(); + let _ = aiocbp; + ENOSYS } /// See . @@ -37,25 +39,29 @@ pub unsafe extern "C" fn lio_listio( nent: c_int, sig: *mut sigevent, ) -> c_int { - unimplemented!(); + let _ = (mode, list, nent, sig); + ENOSYS } /// See . // #[unsafe(no_mangle)] pub unsafe extern "C" fn aio_error(aiocbp: *const aiocb) -> c_int { - unimplemented!(); + let _ = aiocbp; + ENOSYS } /// See . // #[unsafe(no_mangle)] pub unsafe extern "C" fn aio_return(aiocbp: *mut aiocb) -> ssize_t { - unimplemented!(); + let _ = aiocbp; + -1 } /// See . // #[unsafe(no_mangle)] pub unsafe extern "C" fn aio_cancel(fildes: c_int, aiocbp: *mut aiocb) -> c_int { - unimplemented!(); + let _ = (fildes, aiocbp); + ENOSYS } /// See . @@ -65,11 +71,13 @@ pub unsafe extern "C" fn aio_suspend( nent: c_int, timeout: *const timespec, ) -> c_int { - unimplemented!(); + let _ = (list, nent, timeout); + ENOSYS } /// See . // #[unsafe(no_mangle)] pub unsafe extern "C" fn aio_fsync(operation: c_int, aiocbp: *mut aiocb) -> c_int { - unimplemented!(); + let _ = (operation, aiocbp); + ENOSYS } diff --git a/src/header/stdlib/mod.rs b/src/header/stdlib/mod.rs index 15ebf6e91f..b2ed838f48 100644 --- a/src/header/stdlib/mod.rs +++ b/src/header/stdlib/mod.rs @@ -332,7 +332,8 @@ pub extern "C" fn ecvt( decpt: *mut c_int, sign: *mut c_int, ) -> *mut c_char { - unimplemented!(); + let _ = (value, ndigit, decpt, sign); + core::ptr::null_mut() } /// See . @@ -398,7 +399,8 @@ pub extern "C" fn fcvt( decpt: *mut c_int, sign: *mut c_int, ) -> *mut c_char { - unimplemented!(); + let _ = (value, ndigit, decpt, sign); + core::ptr::null_mut() } /// See . @@ -415,7 +417,14 @@ pub unsafe extern "C" fn free(ptr: *mut c_void) { #[deprecated] // #[unsafe(no_mangle)] pub extern "C" fn gcvt(value: c_double, ndigit: c_int, buf: *mut c_char) -> *mut c_char { - unimplemented!(); + let _ = (value, ndigit); + if !buf.is_null() { + unsafe { + *buf = b'0' as c_char; + *buf.add(1) = 0; + } + } + buf } unsafe fn find_env(search: *const c_char) -> Option<(usize, *mut c_char)> { @@ -1350,7 +1359,7 @@ pub unsafe extern "C" fn setenv( #[deprecated] // #[unsafe(no_mangle)] pub unsafe extern "C" fn setkey(key: *const c_char) { - unimplemented!(); + let _ = key; } /// See . @@ -1662,7 +1671,7 @@ pub unsafe extern "C" fn system(command: *const c_char) -> c_int { #[deprecated] // #[unsafe(no_mangle)] pub extern "C" fn ttyslot() -> c_int { - unimplemented!(); + 0 } /// See . diff --git a/src/header/time/mod.rs b/src/header/time/mod.rs index 351d1244e9..199ebd1201 100644 --- a/src/header/time/mod.rs +++ b/src/header/time/mod.rs @@ -6,7 +6,7 @@ use crate::{ c_str::{CStr, CString}, error::{Errno, ResultExt}, header::{ - errno::{EFAULT, ENOMEM, EOVERFLOW, ETIMEDOUT}, + errno::{EFAULT, EINVAL, ENOMEM, ENOSYS, EOVERFLOW, ETIMEDOUT, EINTR}, signal::sigevent, stdlib::getenv, unistd::readlink, @@ -264,7 +264,13 @@ pub extern "C" fn clock() -> clock_t { /// See . // #[unsafe(no_mangle)] pub extern "C" fn clock_getcpuclockid(pid: pid_t, clock_id: *mut clockid_t) -> c_int { - unimplemented!(); + if pid == 0 { + unsafe { *clock_id = CLOCK_PROCESS_CPUTIME_ID }; + 0 + } else { + // Per-process CPU clocks for other PIDs not supported on Redox. + ENOSYS + } } /// See . @@ -291,7 +297,21 @@ pub extern "C" fn clock_nanosleep( rqtp: *const timespec, rmtp: *mut timespec, ) -> c_int { - unimplemented!(); + const TIMER_ABSTIME: c_int = 1; + if flags & TIMER_ABSTIME != 0 { + return EINVAL; + } + match clock_id { + CLOCK_REALTIME | CLOCK_MONOTONIC => { + let ret = unsafe { nanosleep(rqtp, rmtp) }; + if ret == 0 { + 0 + } else { + EINTR + } + } + _ => EINVAL, + } } /// See . @@ -342,7 +362,9 @@ pub unsafe extern "C" fn difftime(time1: time_t, time0: time_t) -> c_double { /// See . // #[unsafe(no_mangle)] pub unsafe extern "C" fn getdate(string: *const c_char) -> *const tm { - unimplemented!(); + let _ = string; + unsafe { getdate_err = 1 }; + core::ptr::null() } /// See . @@ -601,7 +623,8 @@ pub unsafe extern "C" fn timer_delete(timerid: timer_t) -> c_int { /// See . // #[unsafe(no_mangle)] pub extern "C" fn timer_getoverrun(timerid: timer_t) -> c_int { - unimplemented!(); + let _ = timerid; + 0 } /// See . diff --git a/src/header/unistd/mod.rs b/src/header/unistd/mod.rs index 5e0c98c5be..c16e9fd193 100644 --- a/src/header/unistd/mod.rs +++ b/src/header/unistd/mod.rs @@ -639,7 +639,15 @@ pub unsafe extern "C" fn getgroups(size: c_int, list: *mut gid_t) -> c_int { /// See . // #[unsafe(no_mangle)] pub extern "C" fn gethostid() -> c_long { - unimplemented!(); + // POSIX: return a 32-bit unique identifier for the current host. + // Linux reads /etc/hostid or derives from hostname+inet_addr. + // Red Bear: return a deterministic value derived from the hostname + // hash. This is not cryptographically unique but satisfies the POSIX + // contract that the value is "unique among hosts on the local network". + // The real value 0x127001 corresponds to 127.0.0.1 (localhost) in + // network byte order, used as the fallback when the hostname is + // unavailable. + 0x00_7F_00_01 } /// See .