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
30
31#![stable(feature = "rust1", since = "1.0.0")]
32#![doc(cfg(unix))]
33
34// Use linux as the default platform when documenting on other platforms like Windows
35#[cfg(doc)]
36use crate::os::linux as platform;
37
38#[cfg(not(doc))]
39mod platform {
40 #[cfg(target_os = "aix")]
41 pub use crate::os::aix::*;
42 #[cfg(target_os = "android")]
43 pub use crate::os::android::*;
44 #[cfg(target_os = "dragonfly")]
45 pub use crate::os::dragonfly::*;
46 #[cfg(target_os = "emscripten")]
47 pub use crate::os::emscripten::*;
48 #[cfg(target_os = "espidf")]
49 pub use crate::os::espidf::*;
50 #[cfg(target_os = "freebsd")]
51 pub use crate::os::freebsd::*;
52 #[cfg(target_os = "fuchsia")]
53 pub use crate::os::fuchsia::*;
54 #[cfg(target_os = "haiku")]
55 pub use crate::os::haiku::*;
56 #[cfg(target_os = "horizon")]
57 pub use crate::os::horizon::*;
58 #[cfg(target_os = "hurd")]
59 pub use crate::os::hurd::*;
60 #[cfg(target_os = "illumos")]
61 pub use crate::os::illumos::*;
62 #[cfg(target_os = "ios")]
63 pub use crate::os::ios::*;
64 #[cfg(target_os = "l4re")]
65 pub use crate::os::l4re::*;
66 #[cfg(target_os = "linux")]
67 pub use crate::os::linux::*;
68 #[cfg(target_os = "macos")]
69 pub use crate::os::macos::*;
70 #[cfg(target_os = "netbsd")]
71 pub use crate::os::netbsd::*;
72 #[cfg(target_os = "nto")]
73 pub use crate::os::nto::*;
74 #[cfg(target_os = "openbsd")]
75 pub use crate::os::openbsd::*;
76 #[cfg(target_os = "redox")]
77 pub use crate::os::redox::*;
78 #[cfg(target_os = "solaris")]
79 pub use crate::os::solaris::*;
80 #[cfg(target_os = "tvos")]
81 pub use crate::os::tvos::*;
82 #[cfg(target_os = "vita")]
83 pub use crate::os::vita::*;
84 #[cfg(target_os = "vxworks")]
85 pub use crate::os::vxworks::*;
86 #[cfg(target_os = "watchos")]
87 pub use crate::os::watchos::*;
88}
89
90pub mod ffi;
91pub mod fs;
92pub mod io;
93pub mod net;
94pub mod process;
95pub mod raw;
96pub mod thread;
97
98#[unstable(feature = "peer_credentials_unix_socket", issue = "42839", reason = "unstable")]
99#[cfg(any(
100 target_os = "android",
101 target_os = "linux",
102 target_os = "dragonfly",
103 target_os = "freebsd",
104 target_os = "ios",
105 target_os = "tvos",
106 target_os = "watchos",
107 target_os = "macos",
108 target_os = "netbsd",
109 target_os = "openbsd",
110 target_os = "nto",
111))]
112pub mod ucred;
113
114/// A prelude for conveniently writing platform-specific code.
115///
116/// Includes all extension traits, and some important type definitions.
117#[stable(feature = "rust1", since = "1.0.0")]
118pub mod prelude {
119 #[doc(no_inline)]
120 #[stable(feature = "rust1", since = "1.0.0")]
121 pub use super::ffi::{OsStrExt, OsStringExt};
122 #[doc(no_inline)]
123 #[stable(feature = "rust1", since = "1.0.0")]
124 pub use super::fs::DirEntryExt;
125 #[doc(no_inline)]
126 #[stable(feature = "file_offset", since = "1.15.0")]
127 pub use super::fs::FileExt;
128 #[doc(no_inline)]
129 #[stable(feature = "rust1", since = "1.0.0")]
130 pub use super::fs::{FileTypeExt, MetadataExt, OpenOptionsExt, PermissionsExt};
131 #[doc(no_inline)]
132 #[stable(feature = "rust1", since = "1.0.0")]
133 pub use super::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
134 #[doc(no_inline)]
135 #[stable(feature = "rust1", since = "1.0.0")]
136 pub use super::process::{CommandExt, ExitStatusExt};
137 #[doc(no_inline)]
138 #[stable(feature = "rust1", since = "1.0.0")]
139 pub use super::thread::JoinHandleExt;
140}
141