//! Rust friendly bindings to the various *nix system functions. //! //! Modules are structured according to the C header file that they would be //! defined in. //! //! # Features //! //! Nix uses the following Cargo features to enable optional functionality. //! They may be enabled in any combination. //! * `acct` - Process accounting //! * `aio` - POSIX AIO //! * `dir` - Stuff relating to directory iteration //! * `env` - Manipulate environment variables //! * `event` - Event-driven APIs, like `kqueue` and `epoll` //! * `fanotify` - Linux's `fanotify` filesystem events monitoring API //! * `feature` - Query characteristics of the OS at runtime //! * `fs` - File system functionality //! * `hostname` - Get and set the system's hostname //! * `inotify` - Linux's `inotify` file system notification API //! * `ioctl` - The `ioctl` syscall, and wrappers for many specific instances //! * `kmod` - Load and unload kernel modules //! * `mman` - Stuff relating to memory management //! * `mount` - Mount and unmount file systems //! * `mqueue` - POSIX message queues //! * `net` - Networking-related functionality //! * `personality` - Set the process execution domain //! * `poll` - APIs like `poll` and `select` //! * `process` - Stuff relating to running processes //! * `pthread` - POSIX threads //! * `ptrace` - Process tracing and debugging //! * `quota` - File system quotas //! * `reboot` - Reboot the system //! * `resource` - Process resource limits //! * `sched` - Manipulate process's scheduling //! * `socket` - Sockets, whether for networking or local use //! * `signal` - Send and receive signals to processes //! * `syslog` - System logging //! * `term` - Terminal control APIs //! * `time` - Query the operating system's clocks //! * `ucontext` - User thread context //! * `uio` - Vectored I/O //! * `user` - Stuff relating to users and groups //! * `zerocopy` - APIs like `sendfile` and `copy_file_range` #![crate_name = "nix"] #![cfg(unix)] #![allow(non_camel_case_types)] // A clear document is a good document no matter if it has a summary in its // first paragraph or not. #![allow(clippy::too_long_first_doc_paragraph)] #![recursion_limit = "500"] #![deny(unused)] #![deny(unexpected_cfgs)] #![allow(unused_macros)] #![cfg_attr(
not(all(
feature = "acct",
feature = "aio",
feature = "dir",
feature = "env",
feature = "event",
feature = "fanotify",
feature = "feature",
feature = "fs",
feature = "hostname",
feature = "inotify",
feature = "ioctl",
feature = "kmod",
feature = "mman",
feature = "mount",
feature = "mqueue",
feature = "net",
feature = "personality",
feature = "poll",
feature = "process",
feature = "pthread",
feature = "ptrace",
feature = "quota",
feature = "reboot",
feature = "resource",
feature = "sched",
feature = "socket",
feature = "signal",
feature = "syslog",
feature = "term",
feature = "time",
feature = "ucontext",
feature = "uio",
feature = "user",
feature = "zerocopy",
)),
allow(unused_imports)
)] #![deny(unstable_features)] #![deny(missing_copy_implementations)] #![deny(missing_debug_implementations)] #![warn(missing_docs)] #![cfg_attr(docsrs, feature(doc_cfg))] #![deny(clippy::cast_ptr_alignment)] #![deny(unsafe_op_in_unsafe_fn)] // I found the change suggested by this rules could hurt code readability. I cannot // remeber every type's default value, in such cases, it forces me to open // the std doc to insepct the Default value, which is unnecessary with // `.unwrap_or(value)`. #![allow(clippy::unwrap_or_default)]
// Re-exported external crates pubuse libc;
// Private internal modules #[macro_use] mod macros;
use std::ffi::{CStr, CString, OsStr}; use std::mem::MaybeUninit; use std::os::unix::ffi::OsStrExt; use std::path::{Path, PathBuf}; use std::{ptr, result, slice};
use errno::Errno;
/// Nix Result Type pubtype Result<T> = result::Result<T, Errno>;
/// Nix's main error type. /// /// It's a wrapper around Errno. As such, it's very interoperable with /// [`std::io::Error`], but it has the advantages of: /// * `Clone` /// * `Copy` /// * `Eq` /// * Small size /// * Represents all of the system's errnos, instead of just the most common /// ones. pubtype Error = Errno;
/// Common trait used to represent file system paths by many Nix functions. pubtrait NixPath { /// Is the path empty? fn is_empty(&self) -> bool;
/// Length of the path in bytes fn len(&self) -> usize;
/// Execute a function with this path as a `CStr`. /// /// Mostly used internally by Nix. fn with_nix_path<T, F>(&self, f: F) -> Result<T> where
F: FnOnce(&CStr) -> T;
}
fn with_nix_path<T, F>(&self, f: F) -> Result<T> where
F: FnOnce(&CStr) -> T,
{ // The real PATH_MAX is typically 4096, but it's statistically unlikely to have a path // longer than ~300 bytes. See the PR description to get stats for your own machine. // https://github.com/nix-rust/nix/pull/1656 // // By being smaller than a memory page, we also avoid the compiler inserting a probe frame: // https://docs.rs/compiler_builtins/latest/compiler_builtins/probestack/index.html const MAX_STACK_ALLOCATION: usize = 1024;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.