about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAdrian Budau <budau.adi@gmail.com>2018-12-21 15:53:37 +0200
committerAdrian Budau <budau.adi@gmail.com>2018-12-21 15:53:37 +0200
commitbf172c532af44628e3c3323a5f8a8c1726ffbd30 (patch)
treeee41284ce00f1a315d81d16a0b0de57887b20981 /src
parentda47bd3ae01f9a651b652bb141685b128c5058b0 (diff)
downloadrust-bf172c532af44628e3c3323a5f8a8c1726ffbd30.tar.gz
rust-bf172c532af44628e3c3323a5f8a8c1726ffbd30.zip
Properly report ENOSYS by modifying errno
Diffstat (limited to 'src')
-rw-r--r--src/libstd/sys/unix/os.rs15
-rw-r--r--src/libstd/sys/unix/weak.rs25
2 files changed, 18 insertions, 22 deletions
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index 03e81a720dc..6e8ee445994 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -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 {
diff --git a/src/libstd/sys/unix/weak.rs b/src/libstd/sys/unix/weak.rs
index ab75a39eecc..7d293f1c47a 100644
--- a/src/libstd/sys/unix/weak.rs
+++ b/src/libstd/sys/unix/weak.rs
@@ -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) }
-    }
-}