Properly report ENOSYS by modifying errno

This commit is contained in:
Adrian Budau 2018-12-21 15:53:37 +02:00
parent da47bd3ae0
commit bf172c532a
2 changed files with 18 additions and 22 deletions

View File

@ -67,7 +67,8 @@ pub fn errno() -> i32 {
}
/// Sets the platform-specific value of errno
#[cfg(any(target_os = "solaris", target_os = "fuchsia"))] // only needed for readdir so far
#[cfg(all(not(target_os = "linux"),
not(target_os = "dragonfly")))] // needed for readdir and syscall!
pub fn set_errno(e: i32) {
unsafe {
*errno_location() = e as c_int
@ -84,6 +85,18 @@ pub fn errno() -> i32 {
unsafe { errno as i32 }
}
#[cfg(target_os = "dragonfly")]
pub fn set_errno(e: i32) {
extern {
#[thread_local]
static mut errno: c_int;
}
unsafe {
errno = e;
}
}
/// Gets a detailed string description for the given error number.
pub fn error_string(errno: i32) -> String {
extern {

View File

@ -83,13 +83,15 @@ macro_rules! syscall {
(fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => (
unsafe fn $name($($arg_name: $t),*) -> $ret {
use libc;
use super::os;
weak! { fn $name($($t),*) -> $ret }
if let Some(fun) = $name.get() {
fun($($arg_name),*)
} else {
libc::ENOSYS
os::set_errno(libc::ENOSYS);
-1
}
}
)
@ -105,27 +107,8 @@ macro_rules! syscall {
syscall(
concat_idents!(SYS_, $name),
$(::sys::weak::SyscallParam::to_param($arg_name)),*
$($arg_name as c_long),*
) as $ret
}
)
}
#[cfg(target_os = "linux")]
pub trait SyscallParam {
fn to_param(self) -> libc::c_long;
}
#[cfg(target_os = "linux")]
impl SyscallParam for libc::c_int {
fn to_param(self) -> libc::c_long {
self as libc::c_long
}
}
#[cfg(target_os = "linux")]
impl<T> SyscallParam for *mut T {
fn to_param(self) -> libc::c_long {
unsafe { mem::transmute(self) }
}
}