about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2020-07-22 16:38:58 -0700
committerJosh Stone <jistone@redhat.com>2020-07-22 16:38:58 -0700
commitae06e13b8de23722d8bf2fb0143581df07848aa8 (patch)
tree7b6ed366f727ef104c7aa3896d25963ae9625eea /src/libstd
parent37dd7a023b8cef226c73bb9e17b37e379b4ffb48 (diff)
downloadrust-ae06e13b8de23722d8bf2fb0143581df07848aa8.tar.gz
rust-ae06e13b8de23722d8bf2fb0143581df07848aa8.zip
Move the pipe2 call behind a hard target `#[cfg]`
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/sys/unix/os.rs1
-rw-r--r--src/libstd/sys/unix/pipe.rs44
-rw-r--r--src/libstd/sys/unix/weak.rs5
3 files changed, 29 insertions, 21 deletions
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index a9cd5094997..2fcb5b9c4e6 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -71,6 +71,7 @@ pub fn errno() -> i32 {
 
 /// Sets the platform-specific value of errno
 #[cfg(all(not(target_os = "linux"), not(target_os = "dragonfly")))] // needed for readdir and syscall!
+#[allow(dead_code)] // but not all target cfgs actually end up using it
 pub fn set_errno(e: i32) {
     unsafe { *errno_location() = e as c_int }
 }
diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs
index 02a43923708..7ae37bdda70 100644
--- a/src/libstd/sys/unix/pipe.rs
+++ b/src/libstd/sys/unix/pipe.rs
@@ -12,27 +12,29 @@ pub struct AnonPipe(FileDesc);
 pub fn anon_pipe() -> io::Result<(AnonPipe, AnonPipe)> {
     let mut fds = [0; 2];
 
-    // Unfortunately the only known way right now to create atomically set the
-    // CLOEXEC flag is to use the `pipe2` syscall on Linux. This was added in
-    // 2.6.27, glibc 2.9 and musl 0.9.3.
-    if cfg!(any(
-        target_os = "dragonfly",
-        target_os = "freebsd",
-        target_os = "linux",
-        target_os = "netbsd",
-        target_os = "openbsd",
-        target_os = "redox"
-    )) {
-        cvt(unsafe { libc::pipe2(fds.as_mut_ptr(), libc::O_CLOEXEC) })?;
-        Ok((AnonPipe(FileDesc::new(fds[0])), AnonPipe(FileDesc::new(fds[1]))))
-    } else {
-        cvt(unsafe { libc::pipe(fds.as_mut_ptr()) })?;
-
-        let fd0 = FileDesc::new(fds[0]);
-        let fd1 = FileDesc::new(fds[1]);
-        fd0.set_cloexec()?;
-        fd1.set_cloexec()?;
-        Ok((AnonPipe(fd0), AnonPipe(fd1)))
+    // The only known way right now to create atomically set the CLOEXEC flag is
+    // to use the `pipe2` syscall. This was added to Linux in 2.6.27, glibc 2.9
+    // and musl 0.9.3, and some other targets also have it.
+    cfg_if::cfg_if! {
+        if #[cfg(any(
+            target_os = "dragonfly",
+            target_os = "freebsd",
+            target_os = "linux",
+            target_os = "netbsd",
+            target_os = "openbsd",
+            target_os = "redox"
+        ))] {
+            cvt(unsafe { libc::pipe2(fds.as_mut_ptr(), libc::O_CLOEXEC) })?;
+            Ok((AnonPipe(FileDesc::new(fds[0])), AnonPipe(FileDesc::new(fds[1]))))
+        } else {
+            cvt(unsafe { libc::pipe(fds.as_mut_ptr()) })?;
+
+            let fd0 = FileDesc::new(fds[0]);
+            let fd1 = FileDesc::new(fds[1]);
+            fd0.set_cloexec()?;
+            fd1.set_cloexec()?;
+            Ok((AnonPipe(fd0), AnonPipe(fd1)))
+        }
     }
 }
 
diff --git a/src/libstd/sys/unix/weak.rs b/src/libstd/sys/unix/weak.rs
index 08cbe596174..f4b33a00f7c 100644
--- a/src/libstd/sys/unix/weak.rs
+++ b/src/libstd/sys/unix/weak.rs
@@ -16,6 +16,11 @@
 //! symbol, but that caused Debian to detect an unnecessarily strict versioned
 //! dependency on libc6 (#23628).
 
+// There are a variety of `#[cfg]`s controlling which targets are involved in
+// each instance of `weak!` and `syscall!`. Rather than trying to unify all of
+// that, we'll just allow that some unix targets don't use this module at all.
+#![allow(dead_code, unused_macros)]
+
 use crate::ffi::CStr;
 use crate::marker;
 use crate::mem;