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_os = "cygwin")]
45pub use crate::os::cygwin::*;
46#[cfg(target_vendor = "apple")]
47pub use crate::os::darwin::*;
48#[cfg(target_os = "dragonfly")]
49pub use crate::os::dragonfly::*;
50#[cfg(target_os = "emscripten")]
51pub use crate::os::emscripten::*;
52#[cfg(target_os = "espidf")]
53pub use crate::os::espidf::*;
54#[cfg(target_os = "freebsd")]
55pub use crate::os::freebsd::*;
56#[cfg(target_os = "fuchsia")]
57pub use crate::os::fuchsia::*;
58#[cfg(target_os = "haiku")]
59pub use crate::os::haiku::*;
60#[cfg(target_os = "horizon")]
61pub use crate::os::horizon::*;
62#[cfg(target_os = "hurd")]
63pub use crate::os::hurd::*;
64#[cfg(target_os = "illumos")]
65pub use crate::os::illumos::*;
66#[cfg(target_os = "l4re")]
67pub use crate::os::l4re::*;
68#[cfg(target_os = "linux")]
69pub use crate::os::linux::*;
70#[cfg(target_os = "netbsd")]
71pub use crate::os::netbsd::*;
72#[cfg(target_os = "nto")]
73pub use crate::os::nto::*;
74#[cfg(target_os = "nuttx")]
75pub use crate::os::nuttx::*;
76#[cfg(target_os = "openbsd")]
77pub use crate::os::openbsd::*;
78#[cfg(target_os = "redox")]
79pub use crate::os::redox::*;
80#[cfg(target_os = "rtems")]
81pub use crate::os::rtems::*;
82#[cfg(target_os = "solaris")]
83pub use crate::os::solaris::*;
84#[cfg(target_os = "vita")]
85pub use crate::os::vita::*;
86#[cfg(target_os = "vxworks")]
87pub use crate::os::vxworks::*;
88}
8990pub mod ffi;
91pub mod fs;
92pub mod io;
93pub mod net;
94pub mod process;
95pub mod raw;
96pub mod thread;
9798/// A prelude for conveniently writing platform-specific code.
99///
100/// Includes all extension traits, and some important type definitions.
101#[stable(feature = "rust1", since = "1.0.0")]
102pub mod prelude {
103#[doc(no_inline)]
104 #[stable(feature = "rust1", since = "1.0.0")]
105pub use super::ffi::{OsStrExt, OsStringExt};
106#[doc(no_inline)]
107 #[stable(feature = "rust1", since = "1.0.0")]
108pub use super::fs::DirEntryExt;
109#[doc(no_inline)]
110 #[stable(feature = "file_offset", since = "1.15.0")]
111pub use super::fs::FileExt;
112#[doc(no_inline)]
113 #[stable(feature = "rust1", since = "1.0.0")]
114pub use super::fs::{FileTypeExt, MetadataExt, OpenOptionsExt, PermissionsExt};
115#[doc(no_inline)]
116 #[stable(feature = "rust1", since = "1.0.0")]
117pub use super::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
118#[doc(no_inline)]
119 #[stable(feature = "rust1", since = "1.0.0")]
120pub use super::process::{CommandExt, ExitStatusExt};
121#[doc(no_inline)]
122 #[stable(feature = "rust1", since = "1.0.0")]
123pub use super::thread::JoinHandleExt;
124}