1//! Platform-specific extensions to `std` for Unix platforms.
2//!
3//! Provides access to platform-level information on Unix platforms, and
4//! exposes Unix-specific functions that would otherwise be inappropriate as
5//! part of the core `std` library.
6//!
7//! It exposes more ways to deal with platform-specific strings ([`OsStr`],
8//! [`OsString`]), allows to set permissions more granularly, extract low-level
9//! file descriptors from files and sockets, and has platform-specific helpers
10//! for spawning processes.
11//!
12//! # Examples
13//!
14//! ```no_run
15//! use std::fs::File;
16//! use std::os::unix::prelude::*;
17//!
18//! fn main() -> std::io::Result<()> {
19//! let f = File::create("foo.txt")?;
20//! let fd = f.as_raw_fd();
21//!
22//! // use fd with native unix bindings
23//!
24//! Ok(())
25//! }
26//! ```
27//!
28//! [`OsStr`]: crate::ffi::OsStr
29//! [`OsString`]: crate::ffi::OsString
3031#![stable(feature = "rust1", since = "1.0.0")]
32#![doc(cfg(unix))]
3334// Use linux as the default platform when documenting on other platforms like Windows
35#[cfg(doc)]
36use crate::os::linux as platform;
3738#[cfg(not(doc))]
39mod platform {
40#[cfg(target_os = "aix")]
41pub use crate::os::aix::*;
42#[cfg(target_os = "android")]
43pub use crate::os::android::*;
44#[cfg(target_vendor = "apple")]
45pub use crate::os::darwin::*;
46#[cfg(target_os = "dragonfly")]
47pub use crate::os::dragonfly::*;
48#[cfg(target_os = "emscripten")]
49pub use crate::os::emscripten::*;
50#[cfg(target_os = "espidf")]
51pub use crate::os::espidf::*;
52#[cfg(target_os = "freebsd")]
53pub use crate::os::freebsd::*;
54#[cfg(target_os = "fuchsia")]
55pub use crate::os::fuchsia::*;
56#[cfg(target_os = "haiku")]
57pub use crate::os::haiku::*;
58#[cfg(target_os = "horizon")]
59pub use crate::os::horizon::*;
60#[cfg(target_os = "hurd")]
61pub use crate::os::hurd::*;
62#[cfg(target_os = "illumos")]
63pub use crate::os::illumos::*;
64#[cfg(target_os = "l4re")]
65pub use crate::os::l4re::*;
66#[cfg(target_os = "linux")]
67pub use crate::os::linux::*;
68#[cfg(target_os = "netbsd")]
69pub use crate::os::netbsd::*;
70#[cfg(target_os = "nto")]
71pub use crate::os::nto::*;
72#[cfg(target_os = "nuttx")]
73pub use crate::os::nuttx::*;
74#[cfg(target_os = "openbsd")]
75pub use crate::os::openbsd::*;
76#[cfg(target_os = "redox")]
77pub use crate::os::redox::*;
78#[cfg(target_os = "rtems")]
79pub use crate::os::rtems::*;
80#[cfg(target_os = "solaris")]
81pub use crate::os::solaris::*;
82#[cfg(target_os = "vita")]
83pub use crate::os::vita::*;
84#[cfg(target_os = "vxworks")]
85pub use crate::os::vxworks::*;
86}
8788pub mod ffi;
89pub mod fs;
90pub mod io;
91pub mod net;
92pub mod process;
93pub mod raw;
94pub mod thread;
9596/// A prelude for conveniently writing platform-specific code.
97///
98/// Includes all extension traits, and some important type definitions.
99#[stable(feature = "rust1", since = "1.0.0")]
100pub mod prelude {
101#[doc(no_inline)]
102 #[stable(feature = "rust1", since = "1.0.0")]
103pub use super::ffi::{OsStrExt, OsStringExt};
104#[doc(no_inline)]
105 #[stable(feature = "rust1", since = "1.0.0")]
106pub use super::fs::DirEntryExt;
107#[doc(no_inline)]
108 #[stable(feature = "file_offset", since = "1.15.0")]
109pub use super::fs::FileExt;
110#[doc(no_inline)]
111 #[stable(feature = "rust1", since = "1.0.0")]
112pub use super::fs::{FileTypeExt, MetadataExt, OpenOptionsExt, PermissionsExt};
113#[doc(no_inline)]
114 #[stable(feature = "rust1", since = "1.0.0")]
115pub use super::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
116#[doc(no_inline)]
117 #[stable(feature = "rust1", since = "1.0.0")]
118pub use super::process::{CommandExt, ExitStatusExt};
119#[doc(no_inline)]
120 #[stable(feature = "rust1", since = "1.0.0")]
121pub use super::thread::JoinHandleExt;
122}