summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorVincent Dagonneau <vincentdagonneau@gmail.com>2020-03-19 11:40:53 +0100
committerAlan Somers <asomers@gmail.com>2021-12-20 18:47:16 -0700
commit5f5b7d4d7a76575673b57e685c13ba2c52c4183e (patch)
tree75b45fc8b1b70750783e89069bc4d90810c500fe /src/sys
parentd1c6fed481638405b0a87e5b7eecf82ce89b2268 (diff)
downloadnix-5f5b7d4d7a76575673b57e685c13ba2c52c4183e.zip
feature-gate most Nix functions
Using features reduces build time and size for consumer crates. By default all features are enabled.
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/aio.rs5
-rw-r--r--src/sys/epoll.rs1
-rw-r--r--src/sys/inotify.rs18
-rw-r--r--src/sys/mman.rs78
-rw-r--r--src/sys/mod.rs175
-rw-r--r--src/sys/pthread.rs10
-rw-r--r--src/sys/ptrace/bsd.rs5
-rw-r--r--src/sys/ptrace/linux.rs5
-rw-r--r--src/sys/resource.rs15
-rw-r--r--src/sys/select.rs8
-rw-r--r--src/sys/sendfile.rs2
-rw-r--r--src/sys/signal.rs46
-rw-r--r--src/sys/socket/addr.rs119
-rw-r--r--src/sys/socket/mod.rs134
-rw-r--r--src/sys/socket/sockopt.rs55
-rw-r--r--src/sys/stat.rs9
-rw-r--r--src/sys/statfs.rs45
-rw-r--r--src/sys/statvfs.rs11
-rw-r--r--src/sys/termios.rs83
-rw-r--r--src/sys/uio.rs9
-rw-r--r--src/sys/wait.rs8
21 files changed, 745 insertions, 96 deletions
diff --git a/src/sys/aio.rs b/src/sys/aio.rs
index e64a2a82..856becb8 100644
--- a/src/sys/aio.rs
+++ b/src/sys/aio.rs
@@ -49,6 +49,7 @@ libc_enum! {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
O_DSYNC
}
}
@@ -797,6 +798,7 @@ impl<'a> Drop for AioCb<'a> {
///
/// The basic structure used to issue multiple AIO operations simultaneously.
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub struct LioCb<'a> {
/// A collection of [`AioCb`]s. All of these will be issued simultaneously
/// by the [`listio`] method.
@@ -828,6 +830,7 @@ unsafe impl<'a> Send for LioCb<'a> {}
unsafe impl<'a> Sync for LioCb<'a> {}
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
impl<'a> LioCb<'a> {
/// Are no [`AioCb`]s contained?
pub fn is_empty(&self) -> bool {
@@ -1036,6 +1039,7 @@ impl<'a> Debug for LioCb<'a> {
// LioCbBuilder must use a Vec to make construction possible when the final size
// is unknown.
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
#[derive(Debug)]
pub struct LioCbBuilder<'a> {
/// A collection of [`AioCb`]s.
@@ -1045,6 +1049,7 @@ pub struct LioCbBuilder<'a> {
}
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
impl<'a> LioCbBuilder<'a> {
/// Initialize an empty `LioCb`
pub fn with_capacity(capacity: usize) -> LioCbBuilder<'a> {
diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs
index 6bc2a253..678c27f9 100644
--- a/src/sys/epoll.rs
+++ b/src/sys/epoll.rs
@@ -19,6 +19,7 @@ libc_bitflags!(
EPOLLHUP;
EPOLLRDHUP;
#[cfg(target_os = "linux")] // Added in 4.5; not in Android.
+ #[cfg_attr(docsrs, doc(cfg(all())))]
EPOLLEXCLUSIVE;
#[cfg(not(target_arch = "mips"))]
EPOLLWAKEUP;
diff --git a/src/sys/inotify.rs b/src/sys/inotify.rs
index 3f5ae22a..d6697a4a 100644
--- a/src/sys/inotify.rs
+++ b/src/sys/inotify.rs
@@ -36,6 +36,7 @@ use crate::unistd::read;
use crate::Result;
use crate::NixPath;
use crate::errno::Errno;
+use cfg_if::cfg_if;
libc_bitflags! {
/// Configuration options for [`inotify_add_watch`](fn.inotify_add_watch.html).
@@ -151,16 +152,15 @@ impl Inotify {
/// Returns an EINVAL error if the watch descriptor is invalid.
///
/// For more information see, [inotify_rm_watch(2)](https://man7.org/linux/man-pages/man2/inotify_rm_watch.2.html).
- #[cfg(target_os = "linux")]
pub fn rm_watch(self, wd: WatchDescriptor) -> Result<()> {
- let res = unsafe { libc::inotify_rm_watch(self.fd, wd.wd) };
-
- Errno::result(res).map(drop)
- }
-
- #[cfg(target_os = "android")]
- pub fn rm_watch(self, wd: WatchDescriptor) -> Result<()> {
- let res = unsafe { libc::inotify_rm_watch(self.fd, wd.wd as u32) };
+ cfg_if! {
+ if #[cfg(target_os = "linux")] {
+ let arg = wd.wd;
+ } else if #[cfg(target_os = "android")] {
+ let arg = wd.wd as u32;
+ }
+ }
+ let res = unsafe { libc::inotify_rm_watch(self.fd, arg) };
Errno::result(res).map(drop)
}
diff --git a/src/sys/mman.rs b/src/sys/mman.rs
index 0ef1ca8a..017c3f6e 100644
--- a/src/sys/mman.rs
+++ b/src/sys/mman.rs
@@ -5,10 +5,9 @@ use crate::Result;
use crate::NixPath;
use crate::errno::Errno;
#[cfg(not(target_os = "android"))]
-use crate::fcntl::OFlag;
+#[cfg(feature = "fs")]
+use crate::{fcntl::OFlag, sys::stat::Mode};
use libc::{self, c_int, c_void, size_t, off_t};
-#[cfg(not(target_os = "android"))]
-use crate::sys::stat::Mode;
use std::os::unix::io::RawFd;
libc_bitflags!{
@@ -24,9 +23,11 @@ libc_bitflags!{
PROT_EXEC;
/// Apply protection up to the end of a mapping that grows upwards.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PROT_GROWSDOWN;
/// Apply protection down to the beginning of a mapping that grows downwards.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PROT_GROWSUP;
}
}
@@ -45,6 +46,7 @@ libc_bitflags!{
/// To be used with `MAP_FIXED`, to forbid the system
/// to select a different address than the one specified.
#[cfg(target_os = "freebsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_EXCL;
/// Synonym for `MAP_ANONYMOUS`.
MAP_ANON;
@@ -55,98 +57,128 @@ libc_bitflags!{
any(target_arch = "x86", target_arch = "x86_64")),
all(target_os = "linux", target_env = "musl", any(target_arch = "x86", target_arch = "x86_64")),
all(target_os = "freebsd", target_pointer_width = "64")))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_32BIT;
/// Used for stacks; indicates to the kernel that the mapping should extend downward in memory.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_GROWSDOWN;
/// Compatibility flag. Ignored.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_DENYWRITE;
/// Compatibility flag. Ignored.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_EXECUTABLE;
/// Mark the mmaped region to be locked in the same way as `mlock(2)`.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_LOCKED;
/// Do not reserve swap space for this mapping.
///
/// This was removed in FreeBSD 11 and is unused in DragonFlyBSD.
#[cfg(not(any(target_os = "dragonfly", target_os = "freebsd")))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_NORESERVE;
/// Populate page tables for a mapping.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_POPULATE;
/// Only meaningful when used with `MAP_POPULATE`. Don't perform read-ahead.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_NONBLOCK;
/// Allocate the mapping using "huge pages."
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGETLB;
/// Make use of 64KB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_64KB;
/// Make use of 512KB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_512KB;
/// Make use of 1MB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_1MB;
/// Make use of 2MB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_2MB;
/// Make use of 8MB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_8MB;
/// Make use of 16MB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_16MB;
/// Make use of 32MB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_32MB;
/// Make use of 256MB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_256MB;
/// Make use of 512MB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_512MB;
/// Make use of 1GB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_1GB;
/// Make use of 2GB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_2GB;
/// Make use of 16GB huge page (must be supported by the system)
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HUGE_16GB;
/// Lock the mapped region into memory as with `mlock(2)`.
#[cfg(target_os = "netbsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_WIRED;
/// Causes dirtied data in the specified range to be flushed to disk only when necessary.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_NOSYNC;
/// Rename private pages to a file.
///
/// This was removed in FreeBSD 11 and is unused in DragonFlyBSD.
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_RENAME;
/// Region may contain semaphores.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_HASSEMAPHORE;
/// Region grows down, like a stack.
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux", target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_STACK;
/// Pages in this mapping are not retained in the kernel's memory cache.
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_NOCACHE;
/// Allows the W/X bit on the page, it's necessary on aarch64 architecture.
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_JIT;
/// Allows to use large pages, underlying alignment based on size.
#[cfg(target_os = "freebsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_ALIGNED_SUPER;
/// Pages will be discarded in the core dumps.
#[cfg(target_os = "openbsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_CONCEAL;
}
}
@@ -157,15 +189,19 @@ libc_bitflags!{
pub struct MRemapFlags: c_int {
/// Permit the kernel to relocate the mapping to a new virtual address, if necessary.
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MREMAP_MAYMOVE;
/// Place the mapping at exactly the address specified in `new_address`.
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MREMAP_FIXED;
/// Permits to use the old and new address as hints to relocate the mapping.
#[cfg(target_os = "netbsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_FIXED;
/// Allows to duplicate the mapping to be able to apply different flags on the copy.
#[cfg(target_os = "netbsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MAP_REMAPDUP;
}
}
@@ -189,23 +225,29 @@ libc_enum!{
MADV_DONTNEED,
/// Free up a given range of pages and its associated backing store.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_REMOVE,
/// Do not make pages in this range available to the child after a `fork(2)`.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_DONTFORK,
/// Undo the effect of `MADV_DONTFORK`.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_DOFORK,
/// Poison the given pages.
///
/// Subsequent references to those pages are treated like hardware memory corruption.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_HWPOISON,
/// Enable Kernel Samepage Merging (KSM) for the given pages.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_MERGEABLE,
/// Undo the effect of `MADV_MERGEABLE`
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_UNMERGEABLE,
/// Preserve the memory of each page but offline the original page.
#[cfg(any(target_os = "android",
@@ -221,46 +263,61 @@ libc_enum!{
MADV_SOFT_OFFLINE,
/// Enable Transparent Huge Pages (THP) for pages in the given range.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_HUGEPAGE,
/// Undo the effect of `MADV_HUGEPAGE`.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_NOHUGEPAGE,
/// Exclude the given range from a core dump.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_DONTDUMP,
/// Undo the effect of an earlier `MADV_DONTDUMP`.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_DODUMP,
/// Specify that the application no longer needs the pages in the given range.
MADV_FREE,
/// Request that the system not flush the current range to disk unless it needs to.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_NOSYNC,
/// Undoes the effects of `MADV_NOSYNC` for any future pages dirtied within the given range.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_AUTOSYNC,
/// Region is not included in a core file.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_NOCORE,
/// Include region in a core file
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_CORE,
#[cfg(any(target_os = "freebsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_PROTECT,
/// Invalidate the hardware page table for the given region.
#[cfg(target_os = "dragonfly")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_INVAL,
/// Set the offset of the page directory page to `value` for the virtual page table.
#[cfg(target_os = "dragonfly")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_SETMAP,
/// Indicates that the application will not need the data in the given range.
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_ZERO_WIRED_PAGES,
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_FREE_REUSABLE,
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_FREE_REUSE,
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MADV_CAN_REUSE,
}
}
@@ -274,9 +331,11 @@ libc_bitflags!{
MS_INVALIDATE;
/// Invalidate pages, but leave them mapped.
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MS_KILLPAGES;
/// Deactivate pages, but leave them mapped.
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MS_DEACTIVATE;
/// Perform an update and wait for it to complete.
MS_SYNC;
@@ -453,13 +512,21 @@ pub unsafe fn msync(addr: *mut c_void, length: size_t, flags: MsFlags) -> Result
Errno::result(libc::msync(addr, length, flags.bits())).map(drop)
}
+#[cfg(not(target_os = "android"))]
+feature! {
+#![feature = "fs"]
/// Creates and opens a new, or opens an existing, POSIX shared memory object.
///
/// For more information, see [`shm_open(3)`].
///
/// [`shm_open(3)`]: https://man7.org/linux/man-pages/man3/shm_open.3.html
-#[cfg(not(target_os = "android"))]
-pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Result<RawFd> {
+pub fn shm_open<P>(
+ name: &P,
+ flag: OFlag,
+ mode: Mode
+ ) -> Result<RawFd>
+ where P: ?Sized + NixPath
+{
let ret = name.with_nix_path(|cstr| {
#[cfg(any(target_os = "macos", target_os = "ios"))]
unsafe {
@@ -473,6 +540,7 @@ pub fn shm_open<P: ?Sized + NixPath>(name: &P, flag: OFlag, mode: Mode) -> Resul
Errno::result(ret)
}
+}
/// Performs the converse of [`shm_open`], removing an object previously created.
///
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index 156b0d9d..16ba9e0a 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -5,24 +5,31 @@
target_os = "linux",
target_os = "macos",
target_os = "netbsd"))]
-pub mod aio;
-
-#[cfg(any(target_os = "android", target_os = "linux"))]
-#[allow(missing_docs)]
-pub mod epoll;
-
-#[cfg(any(target_os = "dragonfly",
- target_os = "freebsd",
- target_os = "ios",
- target_os = "macos",
- target_os = "netbsd",
- target_os = "openbsd"))]
-#[allow(missing_docs)]
-pub mod event;
-
-#[cfg(any(target_os = "android", target_os = "linux"))]
-#[allow(missing_docs)]
-pub mod eventfd;
+feature! {
+ #![feature = "aio"]
+ pub mod aio;
+}
+
+feature! {
+ #![feature = "event"]
+
+ #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[allow(missing_docs)]
+ pub mod epoll;
+
+ #[cfg(any(target_os = "dragonfly",
+ target_os = "freebsd",
+ target_os = "ios",
+ target_os = "macos",
+ target_os = "netbsd",
+ target_os = "openbsd"))]
+ #[allow(missing_docs)]
+ pub mod event;
+
+ #[cfg(any(target_os = "android", target_os = "linux"))]
+ #[allow(missing_docs)]
+ pub mod eventfd;
+}
#[cfg(any(target_os = "android",
target_os = "dragonfly",
@@ -34,21 +41,35 @@ pub mod eventfd;
target_os = "netbsd",
target_os = "illumos",
target_os = "openbsd"))]
+#[cfg(feature = "ioctl")]
+#[cfg_attr(docsrs, doc(cfg(feature = "ioctl")))]
#[macro_use]
pub mod ioctl;
#[cfg(target_os = "linux")]
-pub mod memfd;
+feature! {
+ #![feature = "fs"]
+ pub mod memfd;
+}
#[cfg(not(target_os = "redox"))]
-#[allow(missing_docs)]
-pub mod mman;
+feature! {
+ #![feature = "mman"]
+ #[allow(missing_docs)]
+ pub mod mman;
+}
#[cfg(target_os = "linux")]
-#[allow(missing_docs)]
-pub mod personality;
+feature! {
+ #![feature = "personality"]
+ #[allow(missing_docs)]
+ pub mod personality;
+}
-pub mod pthread;
+feature! {
+ #![feature = "pthread"]
+ pub mod pthread;
+}
#[cfg(any(target_os = "android",
target_os = "dragonfly",
@@ -57,41 +78,68 @@ pub mod pthread;
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
-#[allow(missing_docs)]
-pub mod ptrace;
+feature! {
+ #![feature = "ptrace"]
+ #[allow(missing_docs)]
+ pub mod ptrace;
+}
#[cfg(target_os = "linux")]
-pub mod quota;
+feature! {
+ #![feature = "quota"]
+ pub mod quota;
+}
-#[cfg(any(target_os = "linux"))]
-#[allow(missing_docs)]
-pub mod reboot;
+#[cfg(target_os = "linux")]
+feature! {
+ #![feature = "reboot"]
+ #[allow(missing_docs)]
+ pub mod reboot;
+}
#[cfg(not(any(target_os = "redox", target_os = "fuchsia", target_os = "illumos")))]
-pub mod resource;
+feature! {
+ #![feature = "resource"]
+ pub mod resource;
+}
#[cfg(not(target_os = "redox"))]
-pub mod select;
+feature! {
+ #![feature = "poll"]
+ pub mod select;
+}
#[cfg(any(target_os = "android",
target_os = "freebsd",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
-pub mod sendfile;
+feature! {
+ #![feature = "zerocopy"]
+ pub mod sendfile;
+}
pub mod signal;
#[cfg(any(target_os = "android", target_os = "linux"))]
-#[allow(missing_docs)]
-pub mod signalfd;
+feature! {
+ #![feature = "signal"]
+ #[allow(missing_docs)]
+ pub mod signalfd;
+}
#[cfg(not(target_os = "redox"))]
-#[allow(missing_docs)]
-pub mod socket;
-
-#[allow(missing_docs)]
-pub mod stat;
+feature! {
+ #![feature = "socket"]
+ #[allow(missing_docs)]
+ pub mod socket;
+}
+
+feature! {
+ #![feature = "fs"]
+ #[allow(missing_docs)]
+ pub mod stat;
+}
#[cfg(any(target_os = "android",
target_os = "dragonfly",
@@ -101,30 +149,55 @@ pub mod stat;
target_os = "macos",
target_os = "openbsd"
))]
-pub mod statfs;
+feature! {
+ #![feature = "fs"]
+ pub mod statfs;
+}
-pub mod statvfs;
+feature! {
+ #![feature = "fs"]
+ pub mod statvfs;
+}
#[cfg(any(target_os = "android", target_os = "linux"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
#[allow(missing_docs)]
pub mod sysinfo;
-#[allow(missing_docs)]
-pub mod termios;
+feature! {
+ #![feature = "term"]
+ #[allow(missing_docs)]
+ pub mod termios;
+}
#[allow(missing_docs)]
pub mod time;
-pub mod uio;
+feature! {
+ #![feature = "uio"]
+ pub mod uio;
+}
-pub mod utsname;
+feature! {
+ #![feature = "features"]
+ pub mod utsname;
+}
-pub mod wait;
+feature! {
+ #![feature = "process"]
+ pub mod wait;
+}
#[cfg(any(target_os = "android", target_os = "linux"))]
-#[allow(missing_docs)]
-pub mod inotify;
+feature! {
+ #![feature = "inotify"]
+ #[allow(missing_docs)]
+ pub mod inotify;
+}
#[cfg(any(target_os = "android", target_os = "linux"))]
-#[allow(missing_docs)]
-pub mod timerfd;
+feature! {
+ #![feature = "time"]
+ #[allow(missing_docs)]
+ pub mod timerfd;
+}
diff --git a/src/sys/pthread.rs b/src/sys/pthread.rs
index d42e45d1..fd81f3ed 100644
--- a/src/sys/pthread.rs
+++ b/src/sys/pthread.rs
@@ -4,8 +4,6 @@
use crate::errno::Errno;
#[cfg(not(target_os = "redox"))]
use crate::Result;
-#[cfg(not(target_os = "redox"))]
-use crate::sys::signal::Signal;
use libc::{self, pthread_t};
/// Identifies an individual thread.
@@ -21,6 +19,9 @@ pub fn pthread_self() -> Pthread {
unsafe { libc::pthread_self() }
}
+feature! {
+#![feature = "signal"]
+
/// Send a signal to a thread (see [`pthread_kill(3)`]).
///
/// If `signal` is `None`, `pthread_kill` will only preform error checking and
@@ -28,7 +29,9 @@ pub fn pthread_self() -> Pthread {
///
/// [`pthread_kill(3)`]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_kill.html
#[cfg(not(target_os = "redox"))]
-pub fn pthread_kill<T: Into<Option<Signal>>>(thread: Pthread, signal: T) -> Result<()> {
+pub fn pthread_kill<T>(thread: Pthread, signal: T) -> Result<()>
+ where T: Into<Option<crate::sys::signal::Signal>>
+{
let sig = match signal.into() {
Some(s) => s as libc::c_int,
None => 0,
@@ -36,3 +39,4 @@ pub fn pthread_kill<T: Into<Option<Signal>>>(thread: Pthread, signal: T) -> Resu
let res = unsafe { libc::pthread_kill(thread, sig) };
Errno::result(res).map(drop)
}
+}
diff --git a/src/sys/ptrace/bsd.rs b/src/sys/ptrace/bsd.rs
index a62881ef..ac7d8312 100644
--- a/src/sys/ptrace/bsd.rs
+++ b/src/sys/ptrace/bsd.rs
@@ -30,10 +30,12 @@ libc_enum! {
PT_READ_I,
PT_READ_D,
#[cfg(target_os = "macos")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PT_READ_U,
PT_WRITE_I,
PT_WRITE_D,
#[cfg(target_os = "macos")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PT_WRITE_U,
PT_CONTINUE,
PT_KILL,
@@ -47,10 +49,13 @@ libc_enum! {
PT_ATTACH,
PT_DETACH,
#[cfg(target_os = "macos")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PT_SIGEXC,
#[cfg(target_os = "macos")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PT_THUPDATE,
#[cfg(target_os = "macos")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PT_ATTACHEXC
}
}
diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs
index 37236790..fb6ff199 100644
--- a/src/sys/ptrace/linux.rs
+++ b/src/sys/ptrace/linux.rs
@@ -99,8 +99,10 @@ libc_enum!{
target_arch = "mips64"))))]
PTRACE_SETREGSET,
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PTRACE_SEIZE,
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PTRACE_INTERRUPT,
#[cfg(all(target_os = "linux", not(any(target_arch = "mips",
target_arch = "mips64"))))]
@@ -171,7 +173,6 @@ libc_bitflags! {
PTRACE_O_TRACESECCOMP;
/// Send a SIGKILL to the tracee if the tracer exits. This is useful
/// for ptrace jailers to prevent tracees from escaping their control.
- #[cfg(any(target_os = "android", target_os = "linux"))]
PTRACE_O_EXITKILL;
}
}
@@ -340,6 +341,7 @@ pub fn attach(pid: Pid) -> Result<()> {
///
/// Attaches to the process specified in pid, making it a tracee of the calling process.
#[cfg(target_os = "linux")]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn seize(pid: Pid, options: Options) -> Result<()> {
unsafe {
ptrace_other(
@@ -388,6 +390,7 @@ pub fn cont<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
///
/// This request is equivalent to `ptrace(PTRACE_INTERRUPT, ...)`
#[cfg(target_os = "linux")]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn interrupt(pid: Pid) -> Result<()> {
unsafe {
ptrace_other(Request::PTRACE_INTERRUPT, pid, ptr::null_mut(), ptr::null_mut()).map(drop)
diff --git a/src/sys/resource.rs b/src/sys/resource.rs
index f3bfb671..80473e58 100644
--- a/src/sys/resource.rs
+++ b/src/sys/resource.rs
@@ -54,6 +54,7 @@ libc_enum! {
target_os = "netbsd",
target_os = "openbsd"
)))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// The maximum amount (in bytes) of virtual memory the process is
/// allowed to map.
RLIMIT_AS,
@@ -72,69 +73,83 @@ libc_enum! {
RLIMIT_STACK,
#[cfg(target_os = "freebsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// The maximum number of kqueues this user id is allowed to create.
RLIMIT_KQUEUES,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// A limit on the combined number of flock locks and fcntl leases that
/// this process may establish.
RLIMIT_LOCKS,
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "openbsd", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// The maximum size (in bytes) which a process may lock into memory
/// using the mlock(2) system call.
RLIMIT_MEMLOCK,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// A limit on the number of bytes that can be allocated for POSIX
/// message queues for the real user ID of the calling process.
RLIMIT_MSGQUEUE,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// A ceiling to which the process's nice value can be raised using
/// setpriority or nice.
RLIMIT_NICE,
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "openbsd", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// The maximum number of simultaneous processes for this user id.
RLIMIT_NPROC,
#[cfg(target_os = "freebsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// The maximum number of pseudo-terminals this user id is allowed to
/// create.
RLIMIT_NPTS,
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "openbsd", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// When there is memory pressure and swap is available, prioritize
/// eviction of a process' resident pages beyond this amount (in bytes).
RLIMIT_RSS,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// A ceiling on the real-time priority that may be set for this process
/// using sched_setscheduler and sched_set‐ param.
RLIMIT_RTPRIO,
#[cfg(any(target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// A limit (in microseconds) on the amount of CPU time that a process
/// scheduled under a real-time scheduling policy may con‐ sume without
/// making a blocking system call.
RLIMIT_RTTIME,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// A limit on the number of signals that may be queued for the real
/// user ID of the calling process.
RLIMIT_SIGPENDING,
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// The maximum size (in bytes) of socket buffer usage for this user.
RLIMIT_SBSIZE,
#[cfg(target_os = "freebsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// The maximum size (in bytes) of the swap space that may be reserved
/// or used by all of this user id's processes.
RLIMIT_SWAP,
#[cfg(target_os = "freebsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// An alias for RLIMIT_AS.
RLIMIT_VMEM,
}
diff --git a/src/sys/select.rs b/src/sys/select.rs
index 4d7576a5..ab4f68f5 100644
--- a/src/sys/select.rs
+++ b/src/sys/select.rs
@@ -8,7 +8,6 @@ use std::ptr::{null, null_mut};
use libc::{self, c_int};
use crate::Result;
use crate::errno::Errno;
-use crate::sys::signal::SigSet;
use crate::sys::time::{TimeSpec, TimeVal};
pub use libc::FD_SETSIZE;
@@ -213,6 +212,11 @@ where
Errno::result(res)
}
+feature! {
+#![feature = "signal"]
+
+use crate::sys::signal::SigSet;
+
/// Monitors file descriptors for readiness with an altered signal mask.
///
/// Returns the total number of ready file descriptors in all sets. The sets are changed so that all
@@ -283,7 +287,7 @@ where
Errno::result(res)
}
-
+}
#[cfg(test)]
mod tests {
diff --git a/src/sys/sendfile.rs b/src/sys/sendfile.rs
index 7a210c6f..1a87a680 100644
--- a/src/sys/sendfile.rs
+++ b/src/sys/sendfile.rs
@@ -22,6 +22,7 @@ use crate::errno::Errno;
///
/// For more information, see [the sendfile(2) man page.](https://man7.org/linux/man-pages/man2/sendfile.2.html)
#[cfg(any(target_os = "android", target_os = "linux"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn sendfile(
out_fd: RawFd,
in_fd: RawFd,
@@ -48,6 +49,7 @@ pub fn sendfile(
///
/// For more information, see [the sendfile(2) man page.](https://man7.org/linux/man-pages/man2/sendfile.2.html)
#[cfg(target_os = "linux")]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn sendfile64(
out_fd: RawFd,
in_fd: RawFd,
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index 61bdc74a..f85bf266 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -5,7 +5,6 @@
use crate::{Error, Result};
use crate::errno::Errno;
-use crate::unistd::Pid;
use std::mem;
use std::fmt;
use std::str::FromStr;
@@ -14,8 +13,10 @@ use std::os::unix::io::RawFd;
use std::ptr;
#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
+#[cfg(any(feature = "aio", feature = "signal"))]
pub use self::sigevent::*;
+#[cfg(any(feature = "aio", feature = "process", feature = "signal"))]
libc_enum!{
/// Types of operating system signals
// Currently there is only one definition of c_int in libc, as well as only one
@@ -24,6 +25,7 @@ libc_enum!{
// this is not (yet) possible.
#[repr(i32)]
#[non_exhaustive]
+ #[cfg_attr(docsrs, doc(cfg(any(feature = "aio", feature = "signal"))))]
pub enum Signal {
/// Hangup
SIGHUP,
@@ -89,6 +91,7 @@ libc_enum!{
SIGIO,
#[cfg(any(target_os = "android", target_os = "emscripten",
target_os = "fuchsia", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// Power failure imminent.
SIGPWR,
/// Bad system call
@@ -96,17 +99,20 @@ libc_enum!{
#[cfg(not(any(target_os = "android", target_os = "emscripten",
target_os = "fuchsia", target_os = "linux",
target_os = "redox")))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// Emulator trap
SIGEMT,
#[cfg(not(any(target_os = "android", target_os = "emscripten",
target_os = "fuchsia", target_os = "linux",
target_os = "redox")))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
/// Information request
SIGINFO,
}
impl TryFrom<i32>
}
+#[cfg(feature = "signal")]
impl FromStr for Signal {
type Err = Error;
fn from_str(s: &str) -> Result<Signal> {
@@ -161,6 +167,7 @@ impl FromStr for Signal {
}
}
+#[cfg(feature = "signal")]
impl Signal {
/// Returns name of signal.
///
@@ -217,21 +224,25 @@ impl Signal {
}
}
+#[cfg(feature = "signal")]
impl AsRef<str> for Signal {
fn as_ref(&self) -> &str {
self.as_str()
}
}
+#[cfg(feature = "signal")]
impl fmt::Display for Signal {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.as_ref())
}
}
+#[cfg(feature = "signal")]
pub use self::Signal::*;
#[cfg(target_os = "redox")]
+#[cfg(feature = "signal")]
const SIGNALS: [Signal; 29] = [
SIGHUP,
SIGINT,
@@ -266,6 +277,7 @@ const SIGNALS: [Signal; 29] = [
target_os = "emscripten", target_os = "fuchsia"),
not(any(target_arch = "mips", target_arch = "mips64",
target_arch = "sparc64"))))]
+#[cfg(feature = "signal")]
const SIGNALS: [Signal; 31] = [
SIGHUP,
SIGINT,
@@ -302,6 +314,7 @@ const SIGNALS: [Signal; 31] = [
target_os = "emscripten", target_os = "fuchsia"),
any(target_arch = "mips", target_arch = "mips64",
target_arch = "sparc64")))]
+#[cfg(feature = "signal")]
const SIGNALS: [Signal; 30] = [
SIGHUP,
SIGINT,
@@ -336,6 +349,7 @@ const SIGNALS: [Signal; 30] = [
#[cfg(not(any(target_os = "linux", target_os = "android",
target_os = "fuchsia", target_os = "emscripten",
target_os = "redox")))]
+#[cfg(feature = "signal")]
const SIGNALS: [Signal; 31] = [
SIGHUP,
SIGINT,
@@ -369,6 +383,9 @@ const SIGNALS: [Signal; 31] = [
SIGEMT,
SIGINFO];
+feature! {
+#![feature = "signal"]
+
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
/// Iterate through all signals defined by this operating system
pub struct SignalIterator {
@@ -407,9 +424,12 @@ pub const SIGUNUSED : Signal = SIGSYS;
type SaFlags_t = libc::c_int;
#[cfg(target_os = "redox")]
type SaFlags_t = libc::c_ulong;
+}
+#[cfg(feature = "signal")]
libc_bitflags!{
/// Controls the behavior of a [`SigAction`]
+ #[cfg_attr(docsrs, doc(cfg(feature = "signal")))]
pub struct SaFlags: SaFlags_t {
/// When catching a [`Signal::SIGCHLD`] signal, the signal will be
/// generated only when a child process exits, not when a child process
@@ -435,10 +455,12 @@ libc_bitflags!{
}
}
+#[cfg(feature = "signal")]
libc_enum! {
/// Specifies how certain functions should manipulate a signal mask
#[repr(i32)]
#[non_exhaustive]
+ #[cfg_attr(docsrs, doc(cfg(feature = "signal")))]
pub enum SigmaskHow {
/// The new mask is the union of the current mask and the specified set.
SIG_BLOCK,
@@ -450,13 +472,17 @@ libc_enum! {
}
}
+feature! {
+#![feature = "signal"]
+
+use crate::unistd::Pid;
+
/// Specifies a set of [`Signal`]s that may be blocked, waited for, etc.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct SigSet {
sigset: libc::sigset_t
}
-
impl SigSet {
/// Initialize to include all signals.
pub fn all() -> SigSet {
@@ -542,6 +568,7 @@ impl SigSet {
/// Suspends execution of the calling thread until one of the signals in the
/// signal mask becomes pending, and returns the accepted signal.
#[cfg(not(target_os = "redox"))] // RedoxFS does not yet support sigwait
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn wait(&self) -> Result<Signal> {
use std::convert::TryFrom;
@@ -573,6 +600,7 @@ pub enum SigHandler {
/// Use the given signal-catching function, which takes in the signal, information about how
/// the signal was generated, and a pointer to the threads `ucontext_t`.
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
SigAction(extern fn(libc::c_int, *mut libc::siginfo_t, *mut libc::c_void))
}
@@ -636,6 +664,7 @@ impl SigAction {
/// Returns the action's handler.
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn handler(&self) -> SigHandler {
match self.sigaction.sa_sigaction {
libc::SIG_DFL => SigHandler::SigDfl,
@@ -670,6 +699,7 @@ impl SigAction {
/// Returns the action's handler.
#[cfg(target_os = "redox")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn handler(&self) -> SigHandler {
match self.sigaction.sa_handler {
libc::SIG_DFL => SigHandler::SigDfl,
@@ -912,7 +942,11 @@ pub fn raise(signal: Signal) -> Result<()> {
Errno::result(res).map(drop)
}
+}
+
+feature! {
+#![any(feature = "aio", feature = "signal")]
/// Identifies a thread for [`SigevNotify::SigevThreadId`]
#[cfg(target_os = "freebsd")]
@@ -942,6 +976,7 @@ pub enum SigevNotify {
// expose a way to set the union members needed by SIGEV_THREAD.
/// Notify by delivering an event to a kqueue.
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
SigevKevent {
/// File descriptor of the kqueue to notify.
kq: RawFd,
@@ -950,6 +985,7 @@ pub enum SigevNotify {
},
/// Notify by delivering a signal to a thread.
#[cfg(any(target_os = "freebsd", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
SigevThreadId {
/// Signal to send
signal: Signal,
@@ -960,9 +996,14 @@ pub enum SigevNotify {
si_value: libc::intptr_t
},
}
+}
#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
mod sigevent {
+ feature! {
+ #![any(feature = "aio", feature = "signal")]
+
use std::mem;
use std::ptr;
use super::SigevNotify;
@@ -1051,6 +1092,7 @@ mod sigevent {
SigEvent{ sigevent: *sigevent }
}
}
+ }
}
#[cfg(test)]
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index b119642b..fa62706e 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -13,7 +13,7 @@ use crate::sys::socket::addr::netlink::NetlinkAddr;
use crate::sys::socket::addr::alg::AlgAddr;
#[cfg(any(target_os = "ios", target_os = "macos"))]
use std::os::unix::io::RawFd;
-#[cfg(any(target_os = "ios", target_os = "macos"))]
+#[cfg(all(feature = "ioctl", any(target_os = "ios", target_os = "macos")))]
use crate::sys::socket::addr::sys_control::SysControlAddr;
#[cfg(any(target_os = "android",
target_os = "dragonfly",
@@ -25,6 +25,7 @@ use crate::sys::socket::addr::sys_control::SysControlAddr;
target_os = "netbsd",
target_os = "openbsd",
target_os = "fuchsia"))]
+#[cfg(feature = "net")]
pub use self::datalink::LinkAddr;
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use self::vsock::VsockAddr;
@@ -43,6 +44,7 @@ pub enum AddressFamily {
Inet6 = libc::AF_INET6,
/// Kernel user interface device (see [`netlink(7)`](https://man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Netlink = libc::AF_NETLINK,
/// Low level packet interface (see [`packet(7)`](https://man7.org/linux/man-pages/man7/packet.7.html))
#[cfg(any(target_os = "android",
@@ -50,84 +52,117 @@ pub enum AddressFamily {
target_os = "illumos",
target_os = "fuchsia",
target_os = "solaris"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Packet = libc::AF_PACKET,
/// KEXT Controls and Notifications
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
System = libc::AF_SYSTEM,
/// Amateur radio AX.25 protocol
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Ax25 = libc::AF_AX25,
/// IPX - Novell protocols
Ipx = libc::AF_IPX,
/// AppleTalk
AppleTalk = libc::AF_APPLETALK,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetRom = libc::AF_NETROM,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Bridge = libc::AF_BRIDGE,
/// Access to raw ATM PVCs
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
AtmPvc = libc::AF_ATMPVC,
/// ITU-T X.25 / ISO-8208 protocol (see [`x25(7)`](https://man7.org/linux/man-pages/man7/x25.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
X25 = libc::AF_X25,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Rose = libc::AF_ROSE,
Decnet = libc::AF_DECnet,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetBeui = libc::AF_NETBEUI,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Security = libc::AF_SECURITY,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Key = libc::AF_KEY,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Ash = libc::AF_ASH,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Econet = libc::AF_ECONET,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
AtmSvc = libc::AF_ATMSVC,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Rds = libc::AF_RDS,
Sna = libc::AF_SNA,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Irda = libc::AF_IRDA,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Pppox = libc::AF_PPPOX,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Wanpipe = libc::AF_WANPIPE,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Llc = libc::AF_LLC,
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Ib = libc::AF_IB,
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Mpls = libc::AF_MPLS,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Can = libc::AF_CAN,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Tipc = libc::AF_TIPC,
#[cfg(not(any(target_os = "illumos",
target_os = "ios",
target_os = "macos",
target_os = "solaris")))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Bluetooth = libc::AF_BLUETOOTH,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Iucv = libc::AF_IUCV,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
RxRpc = libc::AF_RXRPC,
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Isdn = libc::AF_ISDN,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Phonet = libc::AF_PHONET,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Ieee802154 = libc::AF_IEEE802154,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Caif = libc::AF_CAIF,
/// Interface to kernel crypto API
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Alg = libc::AF_ALG,
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Nfc = libc::AF_NFC,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Vsock = libc::AF_VSOCK,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -135,6 +170,7 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ImpLink = libc::AF_IMPLINK,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -142,6 +178,7 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Pup = libc::AF_PUP,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -149,11 +186,13 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Chaos = libc::AF_CHAOS,
#[cfg(any(target_os = "ios",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Ns = libc::AF_NS,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -161,6 +200,7 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Iso = libc::AF_ISO,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -168,6 +208,7 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Datakit = libc::AF_DATAKIT,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -175,6 +216,7 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Ccitt = libc::AF_CCITT,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -182,6 +224,7 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Dli = libc::AF_DLI,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -189,6 +232,7 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Lat = libc::AF_LAT,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -196,6 +240,7 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Hylink = libc::AF_HYLINK,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -204,6 +249,7 @@ pub enum AddressFamily {
target_os = "illumos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Link = libc::AF_LINK,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -211,6 +257,7 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Coip = libc::AF_COIP,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -218,6 +265,7 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Cnt = libc::AF_CNT,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -225,9 +273,11 @@ pub enum AddressFamily {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Natm = libc::AF_NATM,
/// Unspecified address family, (see [`getaddrinfo(3)`](https://man7.org/linux/man-pages/man3/getaddrinfo.3.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Unspec = libc::AF_UNSPEC,
}
@@ -263,6 +313,9 @@ impl AddressFamily {
}
}
+feature! {
+#![feature = "net"]
+
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum InetAddr {
V4(libc::sockaddr_in),
@@ -515,6 +568,7 @@ impl fmt::Display for Ipv6Addr {
self.to_std().fmt(fmt)
}
}
+}
/// A wrapper around `sockaddr_un`.
#[derive(Clone, Copy, Debug)]
@@ -586,6 +640,7 @@ impl UnixAddr {
/// This is a Linux-specific extension, primarily used to allow chrooted
/// processes to communicate with processes having a different filesystem view.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn new_abstract(path: &[u8]) -> Result<UnixAddr> {
unsafe {
let mut ret = libc::sockaddr_un {
@@ -644,6 +699,7 @@ impl UnixAddr {
/// For abstract sockets only the bare name is returned, without the
/// leading null byte. `None` is returned for unnamed or path-backed sockets.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn as_abstract(&self) -> Option<&[u8]> {
match self.kind() {
UnixAddrKind::Abstract(name) => Some(name),
@@ -709,13 +765,18 @@ impl Hash for UnixAddr {
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum SockAddr {
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Inet(InetAddr),
Unix(UnixAddr),
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Netlink(NetlinkAddr),
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Alg(AlgAddr),
- #[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg(all(feature = "ioctl", any(target_os = "ios", target_os = "macos")))]
+ #[cfg_attr(docsrs, doc(cfg(feature = "ioctl")))]
SysControl(SysControlAddr),
/// Datalink address (MAC)
#[cfg(any(target_os = "android",
@@ -727,52 +788,68 @@ pub enum SockAddr {
target_os = "illumos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Link(LinkAddr),
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
Vsock(VsockAddr),
}
impl SockAddr {
+ feature! {
+ #![feature = "net"]
pub fn new_inet(addr: InetAddr) -> SockAddr {
SockAddr::Inet(addr)
}
+ }
pub fn new_unix<P: ?Sized + NixPath>(path: &P) -> Result<SockAddr> {
Ok(SockAddr::Unix(UnixAddr::new(path)?))
}
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn new_netlink(pid: u32, groups: u32) -> SockAddr {
SockAddr::Netlink(NetlinkAddr::new(pid, groups))
}
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn new_alg(alg_type: &str, alg_name: &str) -> SockAddr {
SockAddr::Alg(AlgAddr::new(alg_type, alg_name))
}
+ feature! {
+ #![feature = "ioctl"]
#[cfg(any(target_os = "ios", target_os = "macos"))]
pub fn new_sys_control(sockfd: RawFd, name: &str, unit: u32) -> Result<SockAddr> {
SysControlAddr::from_name(sockfd, name, unit).map(SockAddr::SysControl)
}
+ }
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn new_vsock(cid: u32, port: u32) -> SockAddr {
SockAddr::Vsock(VsockAddr::new(cid, port))
}
pub fn family(&self) -> AddressFamily {
match *self {
+ #[cfg(feature = "net")]
SockAddr::Inet(InetAddr::V4(..)) => AddressFamily::Inet,
+ #[cfg(feature = "net")]
SockAddr::Inet(InetAddr::V6(..)) => AddressFamily::Inet6,
SockAddr::Unix(..) => AddressFamily::Unix,
#[cfg(any(target_os = "android", target_os = "linux"))]
SockAddr::Netlink(..) => AddressFamily::Netlink,
#[cfg(any(target_os = "android", target_os = "linux"))]
SockAddr::Alg(..) => AddressFamily::Alg,
- #[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg(all(feature = "ioctl",
+ any(target_os = "ios", target_os = "macos")))]
SockAddr::SysControl(..) => AddressFamily::System,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(feature = "net")]
SockAddr::Link(..) => AddressFamily::Packet,
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
@@ -781,6 +858,7 @@ impl SockAddr {
target_os = "netbsd",
target_os = "illumos",
target_os = "openbsd"))]
+ #[cfg(feature = "net")]
SockAddr::Link(..) => AddressFamily::Link,
#[cfg(any(target_os = "android", target_os = "linux"))]
SockAddr::Vsock(..) => AddressFamily::Vsock,
@@ -802,23 +880,28 @@ impl SockAddr {
/// unsafe because it takes a raw pointer as argument. The caller must
/// ensure that the pointer is valid.
#[cfg(not(target_os = "fuchsia"))]
+ #[cfg(feature = "net")]
pub(crate) unsafe fn from_libc_sockaddr(addr: *const libc::sockaddr) -> Option<SockAddr> {
if addr.is_null() {
None
} else {
match AddressFamily::from_i32(i32::from((*addr).sa_family)) {
Some(AddressFamily::Unix) => None,
+ #[cfg(feature = "net")]
Some(AddressFamily::Inet) => Some(SockAddr::Inet(
InetAddr::V4(*(addr as *const libc::sockaddr_in)))),
+ #[cfg(feature = "net")]
Some(AddressFamily::Inet6) => Some(SockAddr::Inet(
InetAddr::V6(*(addr as *const libc::sockaddr_in6)))),
#[cfg(any(target_os = "android", target_os = "linux"))]
Some(AddressFamily::Netlink) => Some(SockAddr::Netlink(
NetlinkAddr(*(addr as *const libc::sockaddr_nl)))),
- #[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg(all(feature = "ioctl",
+ any(target_os = "ios", target_os = "macos")))]
Some(AddressFamily::System) => Some(SockAddr::SysControl(
SysControlAddr(*(addr as *const libc::sockaddr_ctl)))),
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(feature = "net")]
Some(AddressFamily::Packet) => Some(SockAddr::Link(
LinkAddr(*(addr as *const libc::sockaddr_ll)))),
#[cfg(any(target_os = "dragonfly",
@@ -828,6 +911,7 @@ impl SockAddr {
target_os = "netbsd",
target_os = "illumos",
target_os = "openbsd"))]
+ #[cfg(feature = "net")]
Some(AddressFamily::Link) => {
let ether_addr = LinkAddr(*(addr as *const libc::sockaddr_dl));
if ether_addr.is_empty() {
@@ -855,6 +939,7 @@ impl SockAddr {
/// a sockaddr * need to take the size of the underlying type as well and then internally cast it back.
pub fn as_ffi_pair(&self) -> (&libc::sockaddr, libc::socklen_t) {
match *self {
+ #[cfg(feature = "net")]
SockAddr::Inet(InetAddr::V4(ref addr)) => (
// This cast is always allowed in C
unsafe {
@@ -862,6 +947,7 @@ impl SockAddr {
},
mem::size_of_val(addr) as libc::socklen_t
),
+ #[cfg(feature = "net")]
SockAddr::Inet(InetAddr::V6(ref addr)) => (
// This cast is always allowed in C
unsafe {
@@ -892,7 +978,8 @@ impl SockAddr {
},
mem::size_of_val(sa) as libc::socklen_t
),
- #[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg(all(feature = "ioctl",
+ any(target_os = "ios", target_os = "macos")))]
SockAddr::SysControl(SysControlAddr(ref sa)) => (
// This cast is always allowed in C
unsafe {
@@ -902,6 +989,7 @@ impl SockAddr {
),
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(feature = "net")]
SockAddr::Link(LinkAddr(ref addr)) => (
// This cast is always allowed in C
unsafe {
@@ -916,6 +1004,7 @@ impl SockAddr {
target_os = "illumos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg(feature = "net")]
SockAddr::Link(LinkAddr(ref addr)) => (
// This cast is always allowed in C
unsafe {
@@ -938,13 +1027,15 @@ impl SockAddr {
impl fmt::Display for SockAddr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
+ #[cfg(feature = "net")]
SockAddr::Inet(ref inet) => inet.fmt(f),
SockAddr::Unix(ref unix) => unix.fmt(f),
#[cfg(any(target_os = "android", target_os = "linux"))]
SockAddr::Netlink(ref nl) => nl.fmt(f),
#[cfg(any(target_os = "android", target_os = "linux"))]
SockAddr::Alg(ref nl) => nl.fmt(f),
- #[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg(all(feature = "ioctl",
+ any(target_os = "ios", target_os = "macos")))]
SockAddr::SysControl(ref sc) => sc.fmt(f),
#[cfg(any(target_os = "android",
target_os = "dragonfly",
@@ -955,6 +1046,7 @@ impl fmt::Display for SockAddr {
target_os = "netbsd",
target_os = "illumos",
target_os = "openbsd"))]
+ #[cfg(feature = "net")]
SockAddr::Link(ref ether_addr) => ether_addr.fmt(f),
#[cfg(any(target_os = "android", target_os = "linux"))]
SockAddr::Vsock(ref svm) => svm.fmt(f),
@@ -963,6 +1055,7 @@ impl fmt::Display for SockAddr {
}
#[cfg(any(target_os = "android", target_os = "linux"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub mod netlink {
use crate::sys::socket::addr::AddressFamily;
use libc::{sa_family_t, sockaddr_nl};
@@ -998,6 +1091,7 @@ pub mod netlink {
}
#[cfg(any(target_os = "android", target_os = "linux"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub mod alg {
use libc::{AF_ALG, sockaddr_alg, c_char};
use std::{fmt, mem, str};
@@ -1060,6 +1154,8 @@ pub mod alg {
}
}
+feature! {
+#![feature = "ioctl"]
#[cfg(any(target_os = "ios", target_os = "macos"))]
pub mod sys_control {
use crate::sys::socket::addr::AddressFamily;
@@ -1130,10 +1226,14 @@ pub mod sys_control {
}
}
}
+}
#[cfg(any(target_os = "android", target_os = "linux", target_os = "fuchsia"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
mod datalink {
+ feature! {
+ #![feature = "net"]
use super::{fmt, AddressFamily};
/// Hardware Address
@@ -1197,6 +1297,7 @@ mod datalink {
addr[5])
}
}
+ }
}
#[cfg(any(target_os = "dragonfly",
@@ -1206,7 +1307,10 @@ mod datalink {
target_os = "illumos",
target_os = "netbsd",
target_os = "openbsd"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
mod datalink {
+ feature! {
+ #![feature = "net"]
use super::{fmt, AddressFamily};
/// Hardware Address
@@ -1216,6 +1320,7 @@ mod datalink {
impl LinkAddr {
/// Total length of sockaddr
#[cfg(not(target_os = "illumos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn len(&self) -> usize {
self.0.sdl_len as usize
}
@@ -1291,9 +1396,11 @@ mod datalink {
addr[5])
}
}
+ }
}
#[cfg(any(target_os = "android", target_os = "linux"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub mod vsock {
use crate::sys::socket::addr::AddressFamily;
use libc::{sa_family_t, sockaddr_vm};
diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs
index 97eea3dc..dcac2818 100644
--- a/src/sys/socket/mod.rs
+++ b/src/sys/socket/mod.rs
@@ -8,10 +8,14 @@ use libc::{self, c_void, c_int, iovec, socklen_t, size_t,
use memoffset::offset_of;
use std::{mem, ptr, slice};
use std::os::unix::io::RawFd;
-#[cfg(all(target_os = "linux"))]
+#[cfg(target_os = "linux")]
+#[cfg(feature = "uio")]
use crate::sys::time::TimeSpec;
-use crate::sys::time::TimeVal;
-use crate::sys::uio::IoVec;
+#[cfg(feature = "uio")]
+use crate::sys::{
+ time::TimeVal,
+ uio::IoVec
+};
mod addr;
#[deny(missing_docs)]
@@ -27,19 +31,27 @@ pub mod sockopt;
pub use self::addr::{
AddressFamily,
SockAddr,
- InetAddr,
UnixAddr,
+};
+#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
+#[cfg(feature = "net")]
+pub use self::addr::{
+ InetAddr,
IpAddr,
Ipv4Addr,
Ipv6Addr,
- LinkAddr,
+ LinkAddr
};
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
pub use self::addr::{
AddressFamily,
SockAddr,
- InetAddr,
UnixAddr,
+};
+#[cfg(any(target_os = "illumos", target_os = "solaris"))]
+#[cfg(feature = "net")]
+pub use self::addr::{
+ InetAddr,
IpAddr,
Ipv4Addr,
Ipv6Addr,
@@ -52,16 +64,16 @@ pub use crate::sys::socket::addr::alg::AlgAddr;
#[cfg(any(target_os = "android", target_os = "linux"))]
pub use crate::sys::socket::addr::vsock::VsockAddr;
+#[cfg(feature = "uio")]
+pub use libc::{cmsghdr, msghdr};
pub use libc::{
- cmsghdr,
- msghdr,
sa_family_t,
sockaddr,
- sockaddr_in,
- sockaddr_in6,
sockaddr_storage,
sockaddr_un,
};
+#[cfg(feature = "net")]
+pub use libc::{sockaddr_in, sockaddr_in6};
// Needed by the cmsg_space macro
#[doc(hidden)]
@@ -105,68 +117,84 @@ pub enum SockProtocol {
/// Allows applications and other KEXTs to be notified when certain kernel events occur
/// ([ref](https://developer.apple.com/library/content/documentation/Darwin/Conceptual/NKEConceptual/control/control.html))
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
KextEvent = libc::SYSPROTO_EVENT,
/// Allows applications to configure and control a KEXT
/// ([ref](https://developer.apple.com/library/content/documentation/Darwin/Conceptual/NKEConceptual/control/control.html))
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
KextControl = libc::SYSPROTO_CONTROL,
/// Receives routing and link updates and may be used to modify the routing tables (both IPv4 and IPv6), IP addresses, link
// parameters, neighbor setups, queueing disciplines, traffic classes and packet classifiers
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkRoute = libc::NETLINK_ROUTE,
/// Reserved for user-mode socket protocols
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkUserSock = libc::NETLINK_USERSOCK,
/// Query information about sockets of various protocol families from the kernel
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkSockDiag = libc::NETLINK_SOCK_DIAG,
/// SELinux event notifications.
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkSELinux = libc::NETLINK_SELINUX,
/// Open-iSCSI
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkISCSI = libc::NETLINK_ISCSI,
/// Auditing
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkAudit = libc::NETLINK_AUDIT,
/// Access to FIB lookup from user space
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkFIBLookup = libc::NETLINK_FIB_LOOKUP,
/// Netfilter subsystem
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkNetFilter = libc::NETLINK_NETFILTER,
/// SCSI Transports
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkSCSITransport = libc::NETLINK_SCSITRANSPORT,
/// Infiniband RDMA
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkRDMA = libc::NETLINK_RDMA,
/// Transport IPv6 packets from netfilter to user space. Used by ip6_queue kernel module.
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkIPv6Firewall = libc::NETLINK_IP6_FW,
/// DECnet routing messages
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkDECNetRoutingMessage = libc::NETLINK_DNRTMSG,
/// Kernel messages to user space
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkKObjectUEvent = libc::NETLINK_KOBJECT_UEVENT,
/// Netlink interface to request information about ciphers registered with the kernel crypto API as well as allow
/// configuration of the kernel crypto API.
/// ([ref](https://www.man7.org/linux/man-pages/man7/netlink.7.html))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NetlinkCrypto = libc::NETLINK_CRYPTO,
}
@@ -181,6 +209,7 @@ libc_bitflags!{
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
SOCK_NONBLOCK;
/// Set close-on-exec on the new descriptor
#[cfg(any(target_os = "android",
@@ -190,13 +219,16 @@ libc_bitflags!{
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
SOCK_CLOEXEC;
/// Return `EPIPE` instead of raising `SIGPIPE`
#[cfg(target_os = "netbsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
SOCK_NOSIGPIPE;
/// For domains `AF_INET(6)`, only allow `connect(2)`, `sendto(2)`, or `sendmsg(2)`
/// to the DNS port (typically 53)
#[cfg(target_os = "openbsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
SOCK_DNS;
}
}
@@ -245,6 +277,7 @@ libc_bitflags!{
/// the socket error queue. (For more details, see
/// [recvfrom(2)](https://linux.die.net/man/2/recvfrom))
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MSG_ERRQUEUE;
/// Set the `close-on-exec` flag for the file descriptor received via a UNIX domain
/// file descriptor using the `SCM_RIGHTS` operation (described in
@@ -259,6 +292,7 @@ libc_bitflags!{
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MSG_CMSG_CLOEXEC;
}
}
@@ -276,11 +310,14 @@ cfg_if! {
impl UnixCredentials {
/// Creates a new instance with the credentials of the current process
pub fn new() -> Self {
- UnixCredentials(libc::ucred {
- pid: crate::unistd::getpid().as_raw(),
- uid: crate::unistd::getuid().as_raw(),
- gid: crate::unistd::getgid().as_raw(),
- })
+ // Safe because these FFI functions are inherently safe
+ unsafe {
+ UnixCredentials(libc::ucred {
+ pid: libc::getpid(),
+ uid: libc::getuid(),
+ gid: libc::getgid()
+ })
+ }
}
/// Returns the process identifier
@@ -347,7 +384,12 @@ cfg_if! {
/// Returns a list group identifiers (the first one being the effective GID)
pub fn groups(&self) -> &[libc::gid_t] {
- unsafe { slice::from_raw_parts(self.0.cmcred_groups.as_ptr() as *const libc::gid_t, self.0.cmcred_ngroups as _) }
+ unsafe {
+ slice::from_raw_parts(
+ self.0.cmcred_groups.as_ptr() as *const libc::gid_t,
+ self.0.cmcred_ngroups as _
+ )
+ }
}
}
@@ -391,6 +433,8 @@ cfg_if!{
}
}
+feature! {
+#![feature = "net"]
/// Request for multicast socket operations
///
/// This is a wrapper type around `ip_mreq`.
@@ -426,6 +470,10 @@ impl Ipv6MembershipRequest {
})
}
}
+}
+
+feature! {
+#![feature = "uio"]
/// Create a buffer large enough for storing some control messages as returned
/// by [`recvmsg`](fn.recvmsg.html).
@@ -531,9 +579,11 @@ pub enum ControlMessageOwned {
ScmRights(Vec<RawFd>),
/// Received version of [`ControlMessage::ScmCredentials`]
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ScmCredentials(UnixCredentials),
/// Received version of [`ControlMessage::ScmCreds`]
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ScmCreds(UnixCredentials),
/// A message of type `SCM_TIMESTAMP`, containing the time the
/// packet was received by the kernel.
@@ -595,6 +645,7 @@ pub enum ControlMessageOwned {
///
/// [Further reading](https://www.kernel.org/doc/html/latest/networking/timestamping.html)
#[cfg(all(target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ScmTimestampns(TimeSpec),
#[cfg(any(
target_os = "android",
@@ -603,6 +654,8 @@ pub enum ControlMessageOwned {
target_os = "macos",
target_os = "netbsd",
))]
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv4PacketInfo(libc::in_pktinfo),
#[cfg(any(
target_os = "android",
@@ -614,6 +667,8 @@ pub enum ControlMessageOwned {
target_os = "openbsd",
target_os = "netbsd",
))]
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv6PacketInfo(libc::in6_pktinfo),
#[cfg(any(
target_os = "freebsd",
@@ -622,6 +677,8 @@ pub enum ControlMessageOwned {
target_os = "netbsd",
target_os = "openbsd",
))]
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv4RecvIf(libc::sockaddr_dl),
#[cfg(any(
target_os = "freebsd",
@@ -630,6 +687,8 @@ pub enum ControlMessageOwned {
target_os = "netbsd",
target_os = "openbsd",
))]
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv4RecvDstAddr(libc::in_addr),
/// UDP Generic Receive Offload (GRO) allows receiving multiple UDP
@@ -641,6 +700,8 @@ pub enum ControlMessageOwned {
/// `UdpGroSegment` socket option should be enabled on a socket
/// to allow receiving GRO packets.
#[cfg(target_os = "linux")]
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
UdpGroSegments(u16),
/// SO_RXQ_OVFL indicates that an unsigned 32 bit value
@@ -652,13 +713,18 @@ pub enum ControlMessageOwned {
/// `RxqOvfl` socket option should be enabled on a socket
/// to allow receiving the drop counter.
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
RxqOvfl(u32),
/// Socket error queue control messages read with the `MSG_ERRQUEUE` flag.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv4RecvErr(libc::sock_extended_err, Option<sockaddr_in>),
/// Socket error queue control messages read with the `MSG_ERRQUEUE` flag.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv6RecvErr(libc::sock_extended_err, Option<sockaddr_in6>),
/// Catch-all variant for unimplemented cmsg types.
@@ -717,6 +783,7 @@ impl ControlMessageOwned {
target_os = "linux",
target_os = "macos"
))]
+ #[cfg(feature = "net")]
(libc::IPPROTO_IPV6, libc::IPV6_PKTINFO) => {
let info = ptr::read_unaligned(p as *const libc::in6_pktinfo);
ControlMessageOwned::Ipv6PacketInfo(info)
@@ -728,6 +795,7 @@ impl ControlMessageOwned {
target_os = "macos",
target_os = "netbsd",
))]
+ #[cfg(feature = "net")]
(libc::IPPROTO_IP, libc::IP_PKTINFO) => {
let info = ptr::read_unaligned(p as *const libc::in_pktinfo);
ControlMessageOwned::Ipv4PacketInfo(info)
@@ -739,6 +807,7 @@ impl ControlMessageOwned {
target_os = "netbsd",
target_os = "openbsd",
))]
+ #[cfg(feature = "net")]
(libc::IPPROTO_IP, libc::IP_RECVIF) => {
let dl = ptr::read_unaligned(p as *const libc::sockaddr_dl);
ControlMessageOwned::Ipv4RecvIf(dl)
@@ -750,11 +819,13 @@ impl ControlMessageOwned {
target_os = "netbsd",
target_os = "openbsd",
))]
+ #[cfg(feature = "net")]
(libc::IPPROTO_IP, libc::IP_RECVDSTADDR) => {
let dl = ptr::read_unaligned(p as *const libc::in_addr);
ControlMessageOwned::Ipv4RecvDstAddr(dl)
},
#[cfg(target_os = "linux")]
+ #[cfg(feature = "net")]
(libc::SOL_UDP, libc::UDP_GRO) => {
let gso_size: u16 = ptr::read_unaligned(p as *const _);
ControlMessageOwned::UdpGroSegments(gso_size)
@@ -765,11 +836,13 @@ impl ControlMessageOwned {
ControlMessageOwned::RxqOvfl(drop_counter)
},
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(feature = "net")]
(libc::IPPROTO_IP, libc::IP_RECVERR) => {
let (err, addr) = Self::recv_err_helper::<sockaddr_in>(p, len);
ControlMessageOwned::Ipv4RecvErr(err, addr)
},
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(feature = "net")]
(libc::IPPROTO_IPV6, libc::IPV6_RECVERR) => {
let (err, addr) = Self::recv_err_helper::<sockaddr_in6>(p, len);
ControlMessageOwned::Ipv6RecvErr(err, addr)
@@ -783,6 +856,7 @@ impl ControlMessageOwned {
}
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(feature = "net")]
unsafe fn recv_err_helper<T>(p: *mut libc::c_uchar, len: usize) -> (libc::sock_extended_err, Option<T>) {
let ee = p as *const libc::sock_extended_err;
let err = ptr::read_unaligned(ee);
@@ -832,6 +906,7 @@ pub enum ControlMessage<'a> {
/// For further information, please refer to the
/// [`unix(7)`](https://man7.org/linux/man-pages/man7/unix.7.html) man page.
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ScmCredentials(&'a UnixCredentials),
/// A message of type `SCM_CREDS`, containing the pid, uid, euid, gid and groups of
/// a process connected to the socket.
@@ -846,6 +921,7 @@ pub enum ControlMessage<'a> {
/// For further information, please refer to the
/// [`unix(4)`](https://www.freebsd.org/cgi/man.cgi?query=unix) man page.
#[cfg(any(target_os = "freebsd", target_os = "dragonfly"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ScmCreds,
/// Set IV for `AF_ALG` crypto API.
@@ -856,6 +932,7 @@ pub enum ControlMessage<'a> {
target_os = "android",
target_os = "linux",
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
AlgSetIv(&'a [u8]),
/// Set crypto operation for `AF_ALG` crypto API. It may be one of
/// `ALG_OP_ENCRYPT` or `ALG_OP_DECRYPT`
@@ -866,6 +943,7 @@ pub enum ControlMessage<'a> {
target_os = "android",
target_os = "linux",
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
AlgSetOp(&'a libc::c_int),
/// Set the length of associated authentication data (AAD) (applicable only to AEAD algorithms)
/// for `AF_ALG` crypto API.
@@ -876,6 +954,7 @@ pub enum ControlMessage<'a> {
target_os = "android",
target_os = "linux",
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
AlgSetAeadAssoclen(&'a u32),
/// UDP GSO makes it possible for applications to generate network packets
@@ -887,6 +966,8 @@ pub enum ControlMessage<'a> {
/// Send buffer should consist of multiple fixed-size wire payloads
/// following one by one, and the last, possibly smaller one.
#[cfg(target_os = "linux")]
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
UdpGsoSegments(&'a u16),
/// Configure the sending addressing and interface for v4
@@ -898,6 +979,8 @@ pub enum ControlMessage<'a> {
target_os = "netbsd",
target_os = "android",
target_os = "ios",))]
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv4PacketInfo(&'a libc::in_pktinfo),
/// Configure the sending addressing and interface for v6
@@ -910,6 +993,8 @@ pub enum ControlMessage<'a> {
target_os = "freebsd",
target_os = "android",
target_os = "ios",))]
+ #[cfg(feature = "net")]
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
Ipv6PacketInfo(&'a libc::in6_pktinfo),
/// SO_RXQ_OVFL indicates that an unsigned 32 bit value
@@ -918,6 +1003,7 @@ pub enum ControlMessage<'a> {
/// socket between the last recieved packet and this
/// received packet.
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
RxqOvfl(&'a u32),
}
@@ -998,16 +1084,19 @@ impl<'a> ControlMessage<'a> {
len as *const _ as *const u8
},
#[cfg(target_os = "linux")]
+ #[cfg(feature = "net")]
ControlMessage::UdpGsoSegments(gso_size) => {
gso_size as *const _ as *const u8
},
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "android",
target_os = "ios",))]
+ #[cfg(feature = "net")]
ControlMessage::Ipv4PacketInfo(info) => info as *const _ as *const u8,
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "freebsd",
target_os = "android", target_os = "ios",))]
+ #[cfg(feature = "net")]
ControlMessage::Ipv6PacketInfo(info) => info as *const _ as *const u8,
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
ControlMessage::RxqOvfl(drop_count) => {
@@ -1050,16 +1139,19 @@ impl<'a> ControlMessage<'a> {
mem::size_of_val(len)
},
#[cfg(target_os = "linux")]
+ #[cfg(feature = "net")]
ControlMessage::UdpGsoSegments(gso_size) => {
mem::size_of_val(gso_size)
},
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "android",
target_os = "ios",))]
+ #[cfg(feature = "net")]
ControlMessage::Ipv4PacketInfo(info) => mem::size_of_val(info),
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "freebsd",
target_os = "android", target_os = "ios",))]
+ #[cfg(feature = "net")]
ControlMessage::Ipv6PacketInfo(info) => mem::size_of_val(info),
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
ControlMessage::RxqOvfl(drop_count) => {
@@ -1080,14 +1172,17 @@ impl<'a> ControlMessage<'a> {
ControlMessage::AlgSetIv(_) | ControlMessage::AlgSetOp(_) |
ControlMessage::AlgSetAeadAssoclen(_) => libc::SOL_ALG,
#[cfg(target_os = "linux")]
+ #[cfg(feature = "net")]
ControlMessage::UdpGsoSegments(_) => libc::SOL_UDP,
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "android",
target_os = "ios",))]
+ #[cfg(feature = "net")]
ControlMessage::Ipv4PacketInfo(_) => libc::IPPROTO_IP,
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "freebsd",
target_os = "android", target_os = "ios",))]
+ #[cfg(feature = "net")]
ControlMessage::Ipv6PacketInfo(_) => libc::IPPROTO_IPV6,
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
ControlMessage::RxqOvfl(_) => libc::SOL_SOCKET,
@@ -1115,16 +1210,19 @@ impl<'a> ControlMessage<'a> {
libc::ALG_SET_AEAD_ASSOCLEN
},
#[cfg(target_os = "linux")]
+ #[cfg(feature = "net")]
ControlMessage::UdpGsoSegments(_) => {
libc::UDP_SEGMENT
},
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "android",
target_os = "ios",))]
+ #[cfg(feature = "net")]
ControlMessage::Ipv4PacketInfo(_) => libc::IP_PKTINFO,
#[cfg(any(target_os = "linux", target_os = "macos",
target_os = "netbsd", target_os = "freebsd",
target_os = "android", target_os = "ios",))]
+ #[cfg(feature = "net")]
ControlMessage::Ipv6PacketInfo(_) => libc::IPV6_PKTINFO,
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
ControlMessage::RxqOvfl(_) => {
@@ -1528,6 +1626,7 @@ pub fn recvmsg<'a>(fd: RawFd, iov: &[IoVec<&mut [u8]>],
Ok(unsafe { read_mhdr(mhdr, r, msg_controllen, address.assume_init(), &mut cmsg_buffer) })
}
+}
/// Create an endpoint for communication
@@ -1818,6 +1917,7 @@ pub fn sockaddr_storage_to_addr(
}
match c_int::from(addr.ss_family) {
+ #[cfg(feature = "net")]
libc::AF_INET => {
assert!(len as usize >= mem::size_of::<sockaddr_in>());
let sin = unsafe {
@@ -1825,6 +1925,7 @@ pub fn sockaddr_storage_to_addr(
};
Ok(SockAddr::Inet(InetAddr::V4(sin)))
}
+ #[cfg(feature = "net")]
libc::AF_INET6 => {
assert!(len as usize >= mem::size_of::<sockaddr_in6>());
let sin6 = unsafe {
@@ -1840,6 +1941,7 @@ pub fn sockaddr_storage_to_addr(
}
}
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg(feature = "net")]
libc::AF_PACKET => {
use libc::sockaddr_ll;
// Don't assert anything about the size.
diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs
index fcb4be81..3ad139ad 100644
--- a/src/sys/socket/sockopt.rs
+++ b/src/sys/socket/sockopt.rs
@@ -17,6 +17,7 @@ use std::os::unix::ffi::OsStrExt;
// Constants
// TCP_CA_NAME_MAX isn't defined in user space include files
#[cfg(any(target_os = "freebsd", target_os = "linux"))]
+#[cfg(feature = "net")]
const TCP_CA_NAME_MAX: usize = 16;
/// Helper for implementing `SetSockOpt` for a given socket option. See
@@ -251,7 +252,9 @@ sockopt_impl!(
/// Permits multiple AF_INET or AF_INET6 sockets to be bound to an
/// identical socket address.
ReusePort, Both, libc::SOL_SOCKET, libc::SO_REUSEPORT, bool);
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Under most circumstances, TCP sends data when it is presented; when
/// outstanding data has not yet been acknowledged, it gathers small amounts
/// of output to be sent in a single packet once an acknowledgement is
@@ -265,20 +268,28 @@ sockopt_impl!(
/// queued messages for the socket have been successfully sent or the
/// linger timeout has been reached.
Linger, Both, libc::SOL_SOCKET, libc::SO_LINGER, libc::linger);
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Join a multicast group
IpAddMembership, SetOnly, libc::IPPROTO_IP, libc::IP_ADD_MEMBERSHIP,
super::IpMembershipRequest);
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Leave a multicast group.
IpDropMembership, SetOnly, libc::IPPROTO_IP, libc::IP_DROP_MEMBERSHIP,
super::IpMembershipRequest);
cfg_if! {
if #[cfg(any(target_os = "android", target_os = "linux"))] {
+ #[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Join an IPv6 multicast group.
Ipv6AddMembership, SetOnly, libc::IPPROTO_IPV6, libc::IPV6_ADD_MEMBERSHIP, super::Ipv6MembershipRequest);
+ #[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Leave an IPv6 multicast group.
Ipv6DropMembership, SetOnly, libc::IPPROTO_IPV6, libc::IPV6_DROP_MEMBERSHIP, super::Ipv6MembershipRequest);
} else if #[cfg(any(target_os = "dragonfly",
@@ -289,26 +300,36 @@ cfg_if! {
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris"))] {
+ #[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Join an IPv6 multicast group.
Ipv6AddMembership, SetOnly, libc::IPPROTO_IPV6,
libc::IPV6_JOIN_GROUP, super::Ipv6MembershipRequest);
+ #[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Leave an IPv6 multicast group.
Ipv6DropMembership, SetOnly, libc::IPPROTO_IPV6,
libc::IPV6_LEAVE_GROUP, super::Ipv6MembershipRequest);
}
}
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Set or read the time-to-live value of outgoing multicast packets for
/// this socket.
IpMulticastTtl, Both, libc::IPPROTO_IP, libc::IP_MULTICAST_TTL, u8);
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Set or read a boolean integer argument that determines whether sent
/// multicast packets should be looped back to the local sockets.
IpMulticastLoop, Both, libc::IPPROTO_IP, libc::IP_MULTICAST_LOOP, bool);
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// If enabled, this boolean option allows binding to an IP address that
/// is nonlocal or does not (yet) exist.
IpFreebind, Both, libc::IPPROTO_IP, libc::IP_FREEBIND, bool);
@@ -347,7 +368,9 @@ sockopt_impl!(
PeerCredentials, GetOnly, libc::SOL_SOCKET, libc::SO_PEERCRED, super::UnixCredentials);
#[cfg(any(target_os = "ios",
target_os = "macos"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Specify the amount of time, in seconds, that the connection must be idle
/// before keepalive probes (if enabled) are sent.
TcpKeepAlive, Both, libc::IPPROTO_TCP, libc::TCP_KEEPALIVE, u32);
@@ -356,7 +379,9 @@ sockopt_impl!(
target_os = "freebsd",
target_os = "linux",
target_os = "nacl"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The time (in seconds) the connection needs to remain idle before TCP
/// starts sending keepalive probes
TcpKeepIdle, Both, libc::IPPROTO_TCP, libc::TCP_KEEPIDLE, u32);
@@ -372,7 +397,9 @@ cfg_if! {
}
}
#[cfg(not(target_os = "openbsd"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The maximum number of keepalive probes TCP should send before
/// dropping the connection.
TcpKeepCount, Both, libc::IPPROTO_TCP, libc::TCP_KEEPCNT, u32);
@@ -384,11 +411,15 @@ sockopt_impl!(
// Not documented by Linux!
TcpRepair, Both, libc::IPPROTO_TCP, libc::TCP_REPAIR, u32);
#[cfg(not(target_os = "openbsd"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The time (in seconds) between individual keepalive probes.
TcpKeepInterval, Both, libc::IPPROTO_TCP, libc::TCP_KEEPINTVL, u32);
#[cfg(any(target_os = "fuchsia", target_os = "linux"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Specifies the maximum amount of time in milliseconds that transmitted
/// data may remain unacknowledged before TCP will forcibly close the
/// corresponding connection
@@ -423,7 +454,9 @@ sockopt_impl!(
/// Bind this socket to a particular device like “eth0”.
BindToDevice, Both, libc::SOL_SOCKET, libc::SO_BINDTODEVICE, OsString<[u8; libc::IFNAMSIZ]>);
#[cfg(any(target_os = "android", target_os = "linux"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
#[allow(missing_docs)]
// Not documented by Linux!
OriginalDst, GetOnly, libc::SOL_IP, libc::SO_ORIGINAL_DST, libc::sockaddr_in);
@@ -440,16 +473,22 @@ sockopt_impl!(
/// Enable or disable the receiving of the `SO_TIMESTAMPNS` control message.
ReceiveTimestampns, Both, libc::SOL_SOCKET, libc::SO_TIMESTAMPNS, bool);
#[cfg(any(target_os = "android", target_os = "linux"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Setting this boolean option enables transparent proxying on this socket.
IpTransparent, Both, libc::SOL_IP, libc::IP_TRANSPARENT, bool);
#[cfg(target_os = "openbsd")]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Allows the socket to be bound to addresses which are not local to the
/// machine, so it can be used to make a transparent proxy.
BindAny, Both, libc::SOL_SOCKET, libc::SO_BINDANY, bool);
#[cfg(target_os = "freebsd")]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Can `bind(2)` to any address, even one not bound to any available
/// network interface in the system.
BindAny, Both, libc::IPPROTO_IP, libc::IP_BINDANY, bool);
@@ -464,7 +503,9 @@ sockopt_impl!(
/// message.
PassCred, Both, libc::SOL_SOCKET, libc::SO_PASSCRED, bool);
#[cfg(any(target_os = "freebsd", target_os = "linux"))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// This option allows the caller to set the TCP congestion control
/// algorithm to be used, on a per-socket basis.
TcpCongestion, Both, libc::IPPROTO_TCP, libc::TCP_CONGESTION, OsString<[u8; TCP_CA_NAME_MAX]>);
@@ -475,7 +516,9 @@ sockopt_impl!(
target_os = "macos",
target_os = "netbsd",
))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Pass an `IP_PKTINFO` ancillary message that contains a pktinfo
/// structure that supplies some information about the incoming packet.
Ipv4PacketInfo, Both, libc::IPPROTO_IP, libc::IP_PKTINFO, bool);
@@ -488,7 +531,9 @@ sockopt_impl!(
target_os = "netbsd",
target_os = "openbsd",
))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Set delivery of the `IPV6_PKTINFO` control message on incoming
/// datagrams.
Ipv6RecvPacketInfo, Both, libc::IPPROTO_IPV6, libc::IPV6_RECVPKTINFO, bool);
@@ -499,7 +544,9 @@ sockopt_impl!(
target_os = "netbsd",
target_os = "openbsd",
))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The `recvmsg(2)` call returns a `struct sockaddr_dl` corresponding to
/// the interface on which the packet was received.
Ipv4RecvIf, Both, libc::IPPROTO_IP, libc::IP_RECVIF, bool);
@@ -510,17 +557,23 @@ sockopt_impl!(
target_os = "netbsd",
target_os = "openbsd",
))]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The `recvmsg(2)` call will return the destination IP address for a UDP
/// datagram.
Ipv4RecvDstAddr, Both, libc::IPPROTO_IP, libc::IP_RECVDSTADDR, bool);
#[cfg(target_os = "linux")]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
#[allow(missing_docs)]
// Not documented by Linux!
UdpGsoSegment, Both, libc::SOL_UDP, libc::UDP_SEGMENT, libc::c_int);
#[cfg(target_os = "linux")]
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
#[allow(missing_docs)]
// Not documented by Linux!
UdpGroSegment, Both, libc::IPPROTO_UDP, libc::UDP_GRO, bool);
@@ -530,7 +583,9 @@ sockopt_impl!(
/// be attached to received skbs indicating the number of packets dropped by
/// the socket since its creation.
RxqOvfl, Both, libc::SOL_SOCKET, libc::SO_RXQ_OVFL, libc::c_int);
+#[cfg(feature = "net")]
sockopt_impl!(
+ #[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// The socket is restricted to sending and receiving IPv6 packets only.
Ipv6V6Only, Both, libc::IPPROTO_IPV6, libc::IPV6_V6ONLY, bool);
#[cfg(any(target_os = "android", target_os = "linux"))]
diff --git a/src/sys/stat.rs b/src/sys/stat.rs
index c8f10419..67a1b7f7 100644
--- a/src/sys/stat.rs
+++ b/src/sys/stat.rs
@@ -54,6 +54,7 @@ pub fn mknod<P: ?Sized + NixPath>(path: &P, kind: SFlag, perm: Mode, dev: dev_t)
/// Create a special or ordinary file, relative to a given directory.
#[cfg(not(any(target_os = "ios", target_os = "macos", target_os = "redox")))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn mknodat<P: ?Sized + NixPath>(
dirfd: RawFd,
path: &P,
@@ -69,18 +70,21 @@ pub fn mknodat<P: ?Sized + NixPath>(
}
#[cfg(target_os = "linux")]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub const fn major(dev: dev_t) -> u64 {
((dev >> 32) & 0xffff_f000) |
((dev >> 8) & 0x0000_0fff)
}
#[cfg(target_os = "linux")]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub const fn minor(dev: dev_t) -> u64 {
((dev >> 12) & 0xffff_ff00) |
((dev ) & 0x0000_00ff)
}
#[cfg(target_os = "linux")]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub const fn makedev(major: u64, minor: u64) -> dev_t {
((major & 0xffff_f000) << 32) |
((major & 0x0000_0fff) << 8) |
@@ -129,6 +133,7 @@ pub fn fstat(fd: RawFd) -> Result<FileStat> {
}
#[cfg(not(target_os = "redox"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn fstatat<P: ?Sized + NixPath>(dirfd: RawFd, pathname: &P, f: AtFlags) -> Result<FileStat> {
let mut dst = mem::MaybeUninit::uninit();
let res = pathname.with_nix_path(|cstr| {
@@ -175,6 +180,7 @@ pub enum FchmodatFlags {
///
/// [fchmodat(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchmodat.html).
#[cfg(not(target_os = "redox"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn fchmodat<P: ?Sized + NixPath>(
dirfd: Option<RawFd>,
path: &P,
@@ -233,6 +239,7 @@ pub fn utimes<P: ?Sized + NixPath>(path: &P, atime: &TimeVal, mtime: &TimeVal) -
target_os = "macos",
target_os = "freebsd",
target_os = "netbsd"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn lutimes<P: ?Sized + NixPath>(path: &P, atime: &TimeVal, mtime: &TimeVal) -> Result<()> {
let times: [libc::timeval; 2] = [*atime.as_ref(), *mtime.as_ref()];
let res = path.with_nix_path(|cstr| unsafe {
@@ -280,6 +287,7 @@ pub enum UtimensatFlags {
///
/// [utimensat(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/utimens.html).
#[cfg(not(target_os = "redox"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn utimensat<P: ?Sized + NixPath>(
dirfd: Option<RawFd>,
path: &P,
@@ -306,6 +314,7 @@ pub fn utimensat<P: ?Sized + NixPath>(
}
#[cfg(not(target_os = "redox"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn mkdirat<P: ?Sized + NixPath>(fd: RawFd, path: &P, mode: Mode) -> Result<()> {
let res = path.with_nix_path(|cstr| {
unsafe { libc::mkdirat(fd, cstr.as_ptr(), mode.bits() as mode_t) }
diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs
index 829be57f..bfb94f48 100644
--- a/src/sys/statfs.rs
+++ b/src/sys/statfs.rs
@@ -11,9 +11,11 @@ use crate::{NixPath, Result, errno::Errno};
/// Identifies a mounted file system
#[cfg(target_os = "android")]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub type fsid_t = libc::__fsid_t;
/// Identifies a mounted file system
#[cfg(not(target_os = "android"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub type fsid_t = libc::fsid_t;
/// Describes a mounted file system
@@ -142,12 +144,14 @@ impl Statfs {
target_os = "ios",
target_os = "macos"
)))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn filesystem_type(&self) -> FsType {
FsType(self.0.f_type)
}
/// Magic code defining system type
#[cfg(not(any(target_os = "linux", target_os = "android")))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn filesystem_type_name(&self) -> &str {
let c_str = unsafe { CStr::from_ptr(self.0.f_fstypename.as_ptr()) };
c_str.to_str().unwrap()
@@ -155,18 +159,21 @@ impl Statfs {
/// Optimal transfer block size
#[cfg(any(target_os = "ios", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn optimal_transfer_size(&self) -> i32 {
self.0.f_iosize
}
/// Optimal transfer block size
#[cfg(target_os = "openbsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn optimal_transfer_size(&self) -> u32 {
self.0.f_iosize
}
/// Optimal transfer block size
#[cfg(all(target_os = "linux", target_arch = "s390x"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn optimal_transfer_size(&self) -> u32 {
self.0.f_bsize
}
@@ -176,30 +183,35 @@ impl Statfs {
target_os = "android",
all(target_os = "linux", target_env = "musl")
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn optimal_transfer_size(&self) -> libc::c_ulong {
self.0.f_bsize
}
/// Optimal transfer block size
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn optimal_transfer_size(&self) -> libc::__fsword_t {
self.0.f_bsize
}
/// Optimal transfer block size
#[cfg(target_os = "dragonfly")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn optimal_transfer_size(&self) -> libc::c_long {
self.0.f_iosize
}
/// Optimal transfer block size
#[cfg(target_os = "freebsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn optimal_transfer_size(&self) -> u64 {
self.0.f_iosize
}
/// Size of a block
#[cfg(any(target_os = "ios", target_os = "macos", target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn block_size(&self) -> u32 {
self.0.f_bsize
}
@@ -207,6 +219,7 @@ impl Statfs {
/// Size of a block
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
#[cfg(all(target_os = "linux", target_arch = "s390x"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn block_size(&self) -> u32 {
self.0.f_bsize
}
@@ -214,6 +227,7 @@ impl Statfs {
/// Size of a block
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
#[cfg(all(target_os = "linux", target_env = "musl"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn block_size(&self) -> libc::c_ulong {
self.0.f_bsize
}
@@ -221,54 +235,63 @@ impl Statfs {
/// Size of a block
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn block_size(&self) -> libc::__fsword_t {
self.0.f_bsize
}
/// Size of a block
#[cfg(target_os = "freebsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn block_size(&self) -> u64 {
self.0.f_bsize
}
/// Size of a block
#[cfg(target_os = "android")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn block_size(&self) -> libc::c_ulong {
self.0.f_bsize
}
/// Size of a block
#[cfg(target_os = "dragonfly")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn block_size(&self) -> libc::c_long {
self.0.f_bsize
}
/// Maximum length of filenames
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn maximum_name_length(&self) -> u32 {
self.0.f_namemax
}
/// Maximum length of filenames
#[cfg(all(target_os = "linux", target_arch = "s390x"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn maximum_name_length(&self) -> u32 {
self.0.f_namelen
}
/// Maximum length of filenames
#[cfg(all(target_os = "linux", target_env = "musl"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn maximum_name_length(&self) -> libc::c_ulong {
self.0.f_namelen
}
/// Maximum length of filenames
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn maximum_name_length(&self) -> libc::__fsword_t {
self.0.f_namelen
}
/// Maximum length of filenames
#[cfg(target_os = "android")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn maximum_name_length(&self) -> libc::c_ulong {
self.0.f_namelen
}
@@ -281,18 +304,21 @@ impl Statfs {
target_os = "freebsd",
target_os = "openbsd",
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks(&self) -> u64 {
self.0.f_blocks
}
/// Total data blocks in filesystem
#[cfg(target_os = "dragonfly")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks(&self) -> libc::c_long {
self.0.f_blocks
}
/// Total data blocks in filesystem
#[cfg(all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks(&self) -> u64 {
self.0.f_blocks
}
@@ -307,6 +333,7 @@ impl Statfs {
target_os = "dragonfly",
all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32")))
)))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks(&self) -> libc::c_ulong {
self.0.f_blocks
}
@@ -319,18 +346,21 @@ impl Statfs {
target_os = "freebsd",
target_os = "openbsd",
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks_free(&self) -> u64 {
self.0.f_bfree
}
/// Free blocks in filesystem
#[cfg(target_os = "dragonfly")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks_free(&self) -> libc::c_long {
self.0.f_bfree
}
/// Free blocks in filesystem
#[cfg(all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks_free(&self) -> u64 {
self.0.f_bfree
}
@@ -345,30 +375,35 @@ impl Statfs {
target_os = "dragonfly",
all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32")))
)))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks_free(&self) -> libc::c_ulong {
self.0.f_bfree
}
/// Free blocks available to unprivileged user
#[cfg(any(target_os = "ios", target_os = "macos", target_os = "android"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks_available(&self) -> u64 {
self.0.f_bavail
}
/// Free blocks available to unprivileged user
#[cfg(target_os = "dragonfly")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks_available(&self) -> libc::c_long {
self.0.f_bavail
}
/// Free blocks available to unprivileged user
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks_available(&self) -> i64 {
self.0.f_bavail
}
/// Free blocks available to unprivileged user
#[cfg(all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks_available(&self) -> u64 {
self.0.f_bavail
}
@@ -383,6 +418,7 @@ impl Statfs {
target_os = "dragonfly",
all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32")))
)))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn blocks_available(&self) -> libc::c_ulong {
self.0.f_bavail
}
@@ -395,18 +431,21 @@ impl Statfs {
target_os = "freebsd",
target_os = "openbsd",
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn files(&self) -> u64 {
self.0.f_files
}
/// Total file nodes in filesystem
#[cfg(target_os = "dragonfly")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn files(&self) -> libc::c_long {
self.0.f_files
}
/// Total file nodes in filesystem
#[cfg(all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn files(&self) -> libc::fsfilcnt_t {
self.0.f_files
}
@@ -421,6 +460,7 @@ impl Statfs {
target_os = "dragonfly",
all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32")))
)))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn files(&self) -> libc::c_ulong {
self.0.f_files
}
@@ -432,24 +472,28 @@ impl Statfs {
target_os = "macos",
target_os = "openbsd"
))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn files_free(&self) -> u64 {
self.0.f_ffree
}
/// Free file nodes in filesystem
#[cfg(target_os = "dragonfly")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn files_free(&self) -> libc::c_long {
self.0.f_ffree
}
/// Free file nodes in filesystem
#[cfg(target_os = "freebsd")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn files_free(&self) -> i64 {
self.0.f_ffree
}
/// Free file nodes in filesystem
#[cfg(all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn files_free(&self) -> libc::fsfilcnt_t {
self.0.f_ffree
}
@@ -464,6 +508,7 @@ impl Statfs {
target_os = "dragonfly",
all(target_os = "linux", any(target_env = "musl", all(target_arch = "x86_64", target_pointer_width = "32")))
)))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn files_free(&self) -> libc::c_ulong {
self.0.f_ffree
}
diff --git a/src/sys/statvfs.rs b/src/sys/statvfs.rs
index 15e7a7d4..ab54b4b5 100644
--- a/src/sys/statvfs.rs
+++ b/src/sys/statvfs.rs
@@ -21,33 +21,43 @@ libc_bitflags!(
ST_NOSUID;
/// Do not interpret character or block-special devices
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ST_NODEV;
/// Do not allow execution of binaries on the filesystem
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ST_NOEXEC;
/// All IO should be done synchronously
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ST_SYNCHRONOUS;
/// Allow mandatory locks on the filesystem
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ST_MANDLOCK;
/// Write on file/directory/symlink
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ST_WRITE;
/// Append-only file
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ST_APPEND;
/// Immutable file
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ST_IMMUTABLE;
/// Do not update access times on files
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ST_NOATIME;
/// Do not update access times on files
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ST_NODIRATIME;
/// Update access time relative to modify/change time
#[cfg(any(target_os = "android", all(target_os = "linux", not(target_env = "musl"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ST_RELATIME;
}
);
@@ -109,6 +119,7 @@ impl Statvfs {
/// Get the mount flags
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
pub fn flags(&self) -> FsFlags {
FsFlags::from_bits_truncate(self.0.f_flag)
}
diff --git a/src/sys/termios.rs b/src/sys/termios.rs
index 01d46080..92204a05 100644
--- a/src/sys/termios.rs
+++ b/src/sys/termios.rs
@@ -160,6 +160,7 @@ use std::convert::From;
use std::mem;
use std::os::unix::io::RawFd;
+#[cfg(feature = "process")]
use crate::unistd::Pid;
/// Stores settings for the termios API
@@ -276,6 +277,7 @@ libc_enum!{
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B7200,
B9600,
#[cfg(any(target_os = "dragonfly",
@@ -283,6 +285,7 @@ libc_enum!{
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B14400,
B19200,
#[cfg(any(target_os = "dragonfly",
@@ -290,6 +293,7 @@ libc_enum!{
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B28800,
B38400,
B57600,
@@ -298,12 +302,15 @@ libc_enum!{
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B76800,
B115200,
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B153600,
B230400,
#[cfg(any(target_os = "illumos", target_os = "solaris"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B307200,
#[cfg(any(target_os = "android",
target_os = "freebsd",
@@ -311,10 +318,13 @@ libc_enum!{
target_os = "linux",
target_os = "netbsd",
target_os = "solaris"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B460800,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B500000,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B576000,
#[cfg(any(target_os = "android",
target_os = "freebsd",
@@ -322,22 +332,31 @@ libc_enum!{
target_os = "linux",
target_os = "netbsd",
target_os = "solaris"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B921600,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B1000000,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B1152000,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B1500000,
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B2000000,
#[cfg(any(target_os = "android", all(target_os = "linux", not(target_arch = "sparc64"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B2500000,
#[cfg(any(target_os = "android", all(target_os = "linux", not(target_arch = "sparc64"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B3000000,
#[cfg(any(target_os = "android", all(target_os = "linux", not(target_arch = "sparc64"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B3500000,
#[cfg(any(target_os = "android", all(target_os = "linux", not(target_arch = "sparc64"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
B4000000,
}
impl TryFrom<libc::speed_t>
@@ -420,6 +439,7 @@ libc_enum! {
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
VDSUSP,
VEOF,
VEOL,
@@ -429,12 +449,14 @@ libc_enum! {
target_os = "freebsd",
target_os = "illumos",
target_os = "solaris"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
VERASE2,
VINTR,
VKILL,
VLNEXT,
#[cfg(not(any(all(target_os = "linux", target_arch = "sparc64"),
target_os = "illumos", target_os = "solaris")))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
VMIN,
VQUIT,
VREPRINT,
@@ -446,18 +468,23 @@ libc_enum! {
target_os = "netbsd",
target_os = "openbsd",
target_os = "solaris"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
VSTATUS,
VSTOP,
VSUSP,
#[cfg(target_os = "linux")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
VSWTC,
#[cfg(any(target_os = "haiku", target_os = "illumos", target_os = "solaris"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
VSWTCH,
#[cfg(not(any(all(target_os = "linux", target_arch = "sparc64"),
target_os = "illumos", target_os = "solaris")))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
VTIME,
VWERASE,
#[cfg(target_os = "dragonfly")]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
VCHECKPT,
}
}
@@ -476,6 +503,7 @@ pub use libc::NCCS;
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub use libc::_POSIX_VDISABLE;
libc_bitflags! {
@@ -493,10 +521,13 @@ libc_bitflags! {
IXON;
IXOFF;
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
IXANY;
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
IMAXBEL;
#[cfg(any(target_os = "android", target_os = "linux", target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
IUTF8;
}
}
@@ -509,6 +540,7 @@ libc_bitflags! {
target_os = "haiku",
target_os = "linux",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
OLCUC;
ONLCR;
OCRNL as tcflag_t;
@@ -519,48 +551,56 @@ libc_bitflags! {
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
OFILL as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
OFDEL as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NL0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NL1 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CR0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CR1 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CR2 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CR3 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "freebsd",
@@ -568,18 +608,21 @@ libc_bitflags! {
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
TAB0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
TAB1 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
TAB2 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "freebsd",
@@ -587,44 +630,52 @@ libc_bitflags! {
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
TAB3 as tcflag_t;
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
XTABS;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
BS0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
BS1 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
VT0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
VT1 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
FF0 as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
FF1 as tcflag_t;
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
@@ -632,12 +683,14 @@ libc_bitflags! {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
OXTABS;
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ONOEOT as tcflag_t;
// Bitmasks for use with OutputFlags to select specific settings
@@ -649,12 +702,14 @@ libc_bitflags! {
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NLDLY as tcflag_t; // FIXME: Datatype needs to be corrected in libc for mac
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CRDLY as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "freebsd",
@@ -662,24 +717,28 @@ libc_bitflags! {
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
TABDLY as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
BSDLY as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
VTDLY as tcflag_t;
#[cfg(any(target_os = "android",
target_os = "haiku",
target_os = "ios",
target_os = "linux",
target_os = "macos"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
FFDLY as tcflag_t;
}
}
@@ -693,6 +752,7 @@ libc_bitflags! {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CIGNORE;
CS5;
CS6;
@@ -705,43 +765,54 @@ libc_bitflags! {
HUPCL;
CLOCAL;
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CRTSCTS;
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CBAUD;
#[cfg(any(target_os = "android", all(target_os = "linux", not(target_arch = "mips"))))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CMSPAR;
#[cfg(any(target_os = "android",
all(target_os = "linux",
not(any(target_arch = "powerpc", target_arch = "powerpc64")))))]
CIBAUD;
#[cfg(any(target_os = "android", target_os = "linux"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CBAUDEX;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
MDMBUF;
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CHWFLOW;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CCTS_OFLOW;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CRTS_IFLOW;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CDTR_IFLOW;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CDSR_OFLOW;
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
CCAR_OFLOW;
// Bitmasks for use with ControlFlags to select specific settings
@@ -756,14 +827,17 @@ libc_bitflags! {
/// Flags for setting any local modes
pub struct LocalFlags: tcflag_t {
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ECHOKE;
ECHOE;
ECHOK;
ECHO;
ECHONL;
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ECHOPRT;
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ECHOCTL;
ISIG;
ICANON;
@@ -773,12 +847,15 @@ libc_bitflags! {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
ALTWERASE;
IEXTEN;
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
EXTPROC;
TOSTOP;
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
FLUSHO;
#[cfg(any(target_os = "freebsd",
target_os = "dragonfly",
@@ -786,8 +863,10 @@ libc_bitflags! {
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
NOKERNINFO;
#[cfg(not(target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PENDIN;
NOFLSH;
}
@@ -927,6 +1006,7 @@ pub fn cfmakeraw(termios: &mut Termios) {
///
/// Note that this is a non-standard function, available on FreeBSD.
#[cfg(target_os = "freebsd")]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn cfmakesane(termios: &mut Termios) {
let inner_termios = unsafe { termios.get_libc_termios_mut() };
unsafe {
@@ -995,6 +1075,8 @@ pub fn tcsendbreak(fd: RawFd, duration: c_int) -> Result<()> {
Errno::result(unsafe { libc::tcsendbreak(fd, duration) }).map(drop)
}
+feature! {
+#![feature = "process"]
/// Get the session controlled by the given terminal (see
/// [tcgetsid(3)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/tcgetsid.html)).
pub fn tcgetsid(fd: RawFd) -> Result<Pid> {
@@ -1002,6 +1084,7 @@ pub fn tcgetsid(fd: RawFd) -> Result<Pid> {
Errno::result(res).map(Pid::from_raw)
}
+}
#[cfg(test)]
mod test {
diff --git a/src/sys/uio.rs b/src/sys/uio.rs
index 3abcde24..52324020 100644
--- a/src/sys/uio.rs
+++ b/src/sys/uio.rs
@@ -31,6 +31,7 @@ pub fn readv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>]) -> Result<usize> {
///
/// See also: [`writev`](fn.writev.html) and [`pwrite`](fn.pwrite.html)
#[cfg(not(target_os = "redox"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>],
offset: off_t) -> Result<usize> {
let res = unsafe {
@@ -48,6 +49,7 @@ pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>],
///
/// See also: [`readv`](fn.readv.html) and [`pread`](fn.pread.html)
#[cfg(not(target_os = "redox"))]
+#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn preadv(fd: RawFd, iov: &[IoVec<&mut [u8]>],
offset: off_t) -> Result<usize> {
let res = unsafe {
@@ -92,6 +94,7 @@ pub fn pread(fd: RawFd, buf: &mut [u8], offset: off_t) -> Result<usize>{
/// is used with [`process_vm_readv`](fn.process_vm_readv.html)
/// and [`process_vm_writev`](fn.process_vm_writev.html).
#[cfg(target_os = "linux")]
+#[cfg_attr(docsrs, doc(cfg(all())))]
#[repr(C)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct RemoteIoVec {
@@ -101,6 +104,9 @@ pub struct RemoteIoVec {
pub len: usize,
}
+feature! {
+#![feature = "process"]
+
/// Write data directly to another process's virtual memory
/// (see [`process_vm_writev`(2)]).
///
@@ -170,6 +176,7 @@ pub fn process_vm_readv(
Errno::result(res).map(|r| r as usize)
}
+}
/// A vector of buffers.
///
@@ -195,7 +202,7 @@ impl<T> IoVec<T> {
}
impl<'a> IoVec<&'a [u8]> {
- #[cfg(target_os = "freebsd")]
+ #[cfg(all(feature = "mount", target_os = "freebsd"))]
pub(crate) fn from_raw_parts(base: *mut c_void, len: usize) -> Self {
IoVec(libc::iovec {
iov_base: base,
diff --git a/src/sys/wait.rs b/src/sys/wait.rs
index ee49e37d..20ca1c19 100644
--- a/src/sys/wait.rs
+++ b/src/sys/wait.rs
@@ -27,6 +27,7 @@ libc_bitflags!(
target_os = "redox",
target_os = "macos",
target_os = "netbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
WEXITED;
/// Report the status of selected processes that have continued from a
/// job control stop by receiving a
@@ -41,6 +42,7 @@ libc_bitflags!(
target_os = "redox",
target_os = "macos",
target_os = "netbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
WSTOPPED;
/// Don't reap, just poll status.
#[cfg(any(target_os = "android",
@@ -51,15 +53,19 @@ libc_bitflags!(
target_os = "redox",
target_os = "macos",
target_os = "netbsd"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
WNOWAIT;
/// Don't wait on children of other threads in this group
#[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
__WNOTHREAD;
/// Wait on all children, regardless of type
#[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
__WALL;
/// Wait for "clone" children only.
#[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
__WCLONE;
}
);
@@ -97,6 +103,7 @@ pub enum WaitStatus {
/// [`nix::sys::ptrace`]: ../ptrace/index.html
/// [`ptrace`(2)]: https://man7.org/linux/man-pages/man2/ptrace.2.html
#[cfg(any(target_os = "linux", target_os = "android"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PtraceEvent(Pid, Signal, c_int),
/// The traced process was stopped by execution of a system call,
/// and `PTRACE_O_TRACESYSGOOD` is in effect. See [`ptrace`(2)] for
@@ -104,6 +111,7 @@ pub enum WaitStatus {
///
/// [`ptrace`(2)]: https://man7.org/linux/man-pages/man2/ptrace.2.html
#[cfg(any(target_os = "linux", target_os = "android"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
PtraceSyscall(Pid),
/// The process was previously stopped but has resumed execution
/// after receiving a `SIGCONT` signal. This is only reported if