2015-01-27 20:20:58 +00:00
|
|
|
|
//! Inspection and manipulation of the process's environment.
|
|
|
|
|
//!
|
2017-01-13 04:10:38 +00:00
|
|
|
|
//! This module contains functions to inspect various aspects such as
|
2015-07-17 03:43:36 +00:00
|
|
|
|
//! environment variables, process arguments, the current directory, and various
|
2015-01-27 20:20:58 +00:00
|
|
|
|
//! other important directories.
|
2017-05-18 08:26:47 +00:00
|
|
|
|
//!
|
|
|
|
|
//! There are several functions and structs in this module that have a
|
|
|
|
|
//! counterpart ending in `os`. Those ending in `os` will return an [`OsString`]
|
2019-12-28 15:05:44 +00:00
|
|
|
|
//! and those without will return a [`String`].
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#![stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
2020-08-27 13:45:01 +00:00
|
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests;
|
|
|
|
|
|
2019-02-10 19:23:21 +00:00
|
|
|
|
use crate::error::Error;
|
|
|
|
|
use crate::ffi::{OsStr, OsString};
|
|
|
|
|
use crate::fmt;
|
|
|
|
|
use crate::io;
|
|
|
|
|
use crate::path::{Path, PathBuf};
|
|
|
|
|
use crate::sys;
|
|
|
|
|
use crate::sys::os as os_imp;
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
2017-02-07 18:43:22 +00:00
|
|
|
|
/// Returns the current working directory as a [`PathBuf`].
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2022-02-03 22:19:36 +00:00
|
|
|
|
/// # Platform-specific behavior
|
|
|
|
|
///
|
2022-03-28 03:58:16 +00:00
|
|
|
|
/// This function [currently] corresponds to the `getcwd` function on Unix
|
2022-02-03 22:19:36 +00:00
|
|
|
|
/// and the `GetCurrentDirectoryW` function on Windows.
|
|
|
|
|
///
|
2022-03-28 03:58:16 +00:00
|
|
|
|
/// [currently]: crate::io#platform-specific-behavior
|
|
|
|
|
///
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// # Errors
|
|
|
|
|
///
|
2017-02-07 18:43:22 +00:00
|
|
|
|
/// Returns an [`Err`] if the current working directory value is invalid.
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// Possible cases:
|
|
|
|
|
///
|
|
|
|
|
/// * Current directory does not exist.
|
|
|
|
|
/// * There are insufficient permissions to access the current directory.
|
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
2018-05-14 02:32:27 +00:00
|
|
|
|
/// fn main() -> std::io::Result<()> {
|
|
|
|
|
/// let path = env::current_dir()?;
|
|
|
|
|
/// println!("The current directory is {}", path.display());
|
|
|
|
|
/// Ok(())
|
|
|
|
|
/// }
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// ```
|
2022-05-25 02:41:40 +00:00
|
|
|
|
#[doc(alias = "pwd")]
|
|
|
|
|
#[doc(alias = "getcwd")]
|
|
|
|
|
#[doc(alias = "GetCurrentDirectory")]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-02-23 18:59:17 +00:00
|
|
|
|
pub fn current_dir() -> io::Result<PathBuf> {
|
2015-01-27 20:20:58 +00:00
|
|
|
|
os_imp::getcwd()
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-17 21:36:24 +00:00
|
|
|
|
/// Changes the current working directory to the specified path.
|
|
|
|
|
///
|
2022-02-03 22:19:36 +00:00
|
|
|
|
/// # Platform-specific behavior
|
|
|
|
|
///
|
2022-03-28 03:58:16 +00:00
|
|
|
|
/// This function [currently] corresponds to the `chdir` function on Unix
|
2022-02-03 22:19:36 +00:00
|
|
|
|
/// and the `SetCurrentDirectoryW` function on Windows.
|
|
|
|
|
///
|
2017-05-17 21:36:24 +00:00
|
|
|
|
/// Returns an [`Err`] if the operation fails.
|
|
|
|
|
///
|
2022-03-28 03:58:16 +00:00
|
|
|
|
/// [currently]: crate::io#platform-specific-behavior
|
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// use std::env;
|
2015-02-23 18:59:17 +00:00
|
|
|
|
/// use std::path::Path;
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
|
|
|
|
/// let root = Path::new("/");
|
|
|
|
|
/// assert!(env::set_current_dir(&root).is_ok());
|
|
|
|
|
/// println!("Successfully changed working directory to {}!", root.display());
|
|
|
|
|
/// ```
|
2021-04-29 19:41:23 +00:00
|
|
|
|
#[doc(alias = "chdir")]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2017-05-17 21:36:24 +00:00
|
|
|
|
pub fn set_current_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
|
|
|
|
|
os_imp::chdir(path.as_ref())
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// An iterator over a snapshot of the environment variables of this process.
|
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// This structure is created by [`env::vars()`]. See its documentation for more.
|
2017-01-13 04:10:38 +00:00
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// [`env::vars()`]: vars
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2019-11-27 18:29:00 +00:00
|
|
|
|
pub struct Vars {
|
|
|
|
|
inner: VarsOs,
|
|
|
|
|
}
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// An iterator over a snapshot of the environment variables of this process.
|
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// This structure is created by [`env::vars_os()`]. See its documentation for more.
|
2017-01-13 04:10:38 +00:00
|
|
|
|
///
|
2020-08-30 13:19:21 +00:00
|
|
|
|
/// [`env::vars_os()`]: vars_os
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2019-11-27 18:29:00 +00:00
|
|
|
|
pub struct VarsOs {
|
|
|
|
|
inner: os_imp::Env,
|
|
|
|
|
}
|
2015-02-11 19:47:53 +00:00
|
|
|
|
|
|
|
|
|
/// Returns an iterator of (variable, value) pairs of strings, for all the
|
|
|
|
|
/// environment variables of the current process.
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
|
|
|
|
/// The returned iterator contains a snapshot of the process's environment
|
2016-09-14 20:41:17 +00:00
|
|
|
|
/// variables at the time of this invocation. Modifications to environment
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// variables afterwards will not be reflected in the returned iterator.
|
|
|
|
|
///
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// # Panics
|
|
|
|
|
///
|
|
|
|
|
/// While iterating, the returned iterator will panic if any key or value in the
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// environment is not valid unicode. If this is not desired, consider using
|
|
|
|
|
/// [`env::vars_os()`].
|
2015-02-11 19:47:53 +00:00
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
|
|
|
|
/// // We will iterate through the references to the element returned by
|
|
|
|
|
/// // env::vars();
|
|
|
|
|
/// for (key, value) in env::vars() {
|
2022-02-12 19:16:17 +00:00
|
|
|
|
/// println!("{key}: {value}");
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2020-08-26 14:30:54 +00:00
|
|
|
|
///
|
|
|
|
|
/// [`env::vars_os()`]: vars_os
|
2021-10-31 02:58:27 +00:00
|
|
|
|
#[must_use]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
pub fn vars() -> Vars {
|
2015-02-11 19:47:53 +00:00
|
|
|
|
Vars { inner: vars_os() }
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// Returns an iterator of (variable, value) pairs of OS strings, for all the
|
|
|
|
|
/// environment variables of the current process.
|
|
|
|
|
///
|
|
|
|
|
/// The returned iterator contains a snapshot of the process's environment
|
2016-09-14 20:41:17 +00:00
|
|
|
|
/// variables at the time of this invocation. Modifications to environment
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// variables afterwards will not be reflected in the returned iterator.
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2021-04-29 11:15:49 +00:00
|
|
|
|
/// Note that the returned iterator will not check if the environment variables
|
|
|
|
|
/// are valid Unicode. If you want to panic on invalid UTF-8,
|
|
|
|
|
/// use the [`vars`] function instead.
|
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// // We will iterate through the references to the element returned by
|
|
|
|
|
/// // env::vars_os();
|
|
|
|
|
/// for (key, value) in env::vars_os() {
|
2022-02-12 19:16:17 +00:00
|
|
|
|
/// println!("{key:?}: {value:?}");
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2021-10-31 02:58:27 +00:00
|
|
|
|
#[must_use]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-02-11 19:47:53 +00:00
|
|
|
|
pub fn vars_os() -> VarsOs {
|
|
|
|
|
VarsOs { inner: os_imp::env() }
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-02-11 19:47:53 +00:00
|
|
|
|
impl Iterator for Vars {
|
|
|
|
|
type Item = (String, String);
|
|
|
|
|
fn next(&mut self) -> Option<(String, String)> {
|
2019-11-27 18:29:00 +00:00
|
|
|
|
self.inner.next().map(|(a, b)| (a.into_string().unwrap(), b.into_string().unwrap()))
|
|
|
|
|
}
|
|
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
|
|
|
self.inner.size_hint()
|
2015-02-11 19:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-29 13:31:47 +00:00
|
|
|
|
#[stable(feature = "std_debug", since = "1.16.0")]
|
2016-11-25 18:21:49 +00:00
|
|
|
|
impl fmt::Debug for Vars {
|
2019-03-01 08:34:11 +00:00
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2021-04-05 11:31:11 +00:00
|
|
|
|
f.debug_struct("Vars").finish_non_exhaustive()
|
2016-11-25 18:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-02-11 19:47:53 +00:00
|
|
|
|
impl Iterator for VarsOs {
|
|
|
|
|
type Item = (OsString, OsString);
|
2019-11-27 18:29:00 +00:00
|
|
|
|
fn next(&mut self) -> Option<(OsString, OsString)> {
|
|
|
|
|
self.inner.next()
|
|
|
|
|
}
|
|
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
|
|
|
self.inner.size_hint()
|
|
|
|
|
}
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-29 13:31:47 +00:00
|
|
|
|
#[stable(feature = "std_debug", since = "1.16.0")]
|
2016-11-25 18:21:49 +00:00
|
|
|
|
impl fmt::Debug for VarsOs {
|
2019-03-01 08:34:11 +00:00
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2021-04-05 11:31:11 +00:00
|
|
|
|
f.debug_struct("VarOs").finish_non_exhaustive()
|
2016-11-25 18:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// Fetches the environment variable `key` from the current process.
|
|
|
|
|
///
|
2017-05-18 08:26:47 +00:00
|
|
|
|
/// # Errors
|
2017-02-18 13:44:56 +00:00
|
|
|
|
///
|
2021-08-17 07:09:58 +00:00
|
|
|
|
/// This function will return an error if the environment variable isn't set.
|
|
|
|
|
///
|
|
|
|
|
/// This function may return an error if the environment variable's name contains
|
|
|
|
|
/// the equal sign character (`=`) or the NUL character.
|
|
|
|
|
///
|
|
|
|
|
/// This function will return an error if the environment variable's value is
|
|
|
|
|
/// not valid Unicode. If this is not desired, consider using [`var_os`].
|
2019-08-11 11:49:02 +00:00
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
|
|
|
|
/// let key = "HOME";
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// match env::var(key) {
|
2022-02-12 19:16:17 +00:00
|
|
|
|
/// Ok(val) => println!("{key}: {val:?}"),
|
|
|
|
|
/// Err(e) => println!("couldn't interpret {key}: {e}"),
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-05-05 23:06:21 +00:00
|
|
|
|
pub fn var<K: AsRef<OsStr>>(key: K) -> Result<String, VarError> {
|
2015-09-09 19:37:59 +00:00
|
|
|
|
_var(key.as_ref())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _var(key: &OsStr) -> Result<String, VarError> {
|
2015-02-11 19:47:53 +00:00
|
|
|
|
match var_os(key) {
|
2015-01-27 20:20:58 +00:00
|
|
|
|
Some(s) => s.into_string().map_err(VarError::NotUnicode),
|
2017-05-17 21:36:24 +00:00
|
|
|
|
None => Err(VarError::NotPresent),
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// Fetches the environment variable `key` from the current process, returning
|
2021-06-09 07:40:31 +00:00
|
|
|
|
/// [`None`] if the variable isn't set or there's another error.
|
2019-08-11 11:49:02 +00:00
|
|
|
|
///
|
2021-04-29 11:15:49 +00:00
|
|
|
|
/// Note that the method will not check if the environment variable
|
|
|
|
|
/// is valid Unicode. If you want to have an error on invalid UTF-8,
|
|
|
|
|
/// use the [`var`] function instead.
|
|
|
|
|
///
|
2021-06-09 07:40:31 +00:00
|
|
|
|
/// # Errors
|
|
|
|
|
///
|
2021-08-17 07:09:58 +00:00
|
|
|
|
/// This function returns an error if the environment variable isn't set.
|
|
|
|
|
///
|
|
|
|
|
/// This function may return an error if the environment variable's name contains
|
|
|
|
|
/// the equal sign character (`=`) or the NUL character.
|
|
|
|
|
///
|
|
|
|
|
/// This function may return an error if the environment variable's value contains
|
|
|
|
|
/// the NUL character.
|
2021-06-09 07:40:31 +00:00
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-02-11 19:47:53 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
|
|
|
|
/// let key = "HOME";
|
|
|
|
|
/// match env::var_os(key) {
|
2022-02-12 19:16:17 +00:00
|
|
|
|
/// Some(val) => println!("{key}: {val:?}"),
|
|
|
|
|
/// None => println!("{key} is not defined in the environment.")
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2021-10-31 02:58:27 +00:00
|
|
|
|
#[must_use]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-05-05 23:06:21 +00:00
|
|
|
|
pub fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString> {
|
2015-09-09 19:37:59 +00:00
|
|
|
|
_var_os(key.as_ref())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn _var_os(key: &OsStr) -> Option<OsString> {
|
2019-11-27 18:29:00 +00:00
|
|
|
|
os_imp::getenv(key)
|
2015-02-11 19:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-18 08:26:47 +00:00
|
|
|
|
/// The error type for operations interacting with environment variables.
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// Possibly returned from [`env::var()`].
|
2017-01-13 04:10:38 +00:00
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// [`env::var()`]: var
|
2015-01-27 20:20:58 +00:00
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone)]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
pub enum VarError {
|
|
|
|
|
/// The specified environment variable was not present in the current
|
|
|
|
|
/// process's environment.
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
NotPresent,
|
|
|
|
|
|
|
|
|
|
/// The specified environment variable was found, but it did not contain
|
|
|
|
|
/// valid unicode data. The found data is returned as a payload of this
|
|
|
|
|
/// variant.
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2016-02-20 00:08:36 +00:00
|
|
|
|
NotUnicode(#[stable(feature = "env", since = "1.0.0")] OsString),
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
impl fmt::Display for VarError {
|
2019-03-01 08:34:11 +00:00
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2015-01-27 20:20:58 +00:00
|
|
|
|
match *self {
|
|
|
|
|
VarError::NotPresent => write!(f, "environment variable not found"),
|
|
|
|
|
VarError::NotUnicode(ref s) => {
|
|
|
|
|
write!(f, "environment variable was not valid unicode: {:?}", s)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
impl Error for VarError {
|
2019-12-01 04:01:48 +00:00
|
|
|
|
#[allow(deprecated)]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
|
match *self {
|
|
|
|
|
VarError::NotPresent => "environment variable not found",
|
|
|
|
|
VarError::NotUnicode(..) => "environment variable was not valid unicode",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-23 05:32:55 +00:00
|
|
|
|
/// Sets the environment variable `key` to the value `value` for the currently running
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// process.
|
|
|
|
|
///
|
2015-04-23 20:59:36 +00:00
|
|
|
|
/// Note that while concurrent access to environment variables is safe in Rust,
|
|
|
|
|
/// some platforms only expose inherently unsafe non-threadsafe APIs for
|
2019-09-05 16:15:28 +00:00
|
|
|
|
/// inspecting the environment. As a result, extra care needs to be taken when
|
2015-04-23 20:59:36 +00:00
|
|
|
|
/// auditing calls to unsafe external FFI functions to ensure that any external
|
|
|
|
|
/// environment accesses are properly synchronized with accesses in Rust.
|
|
|
|
|
///
|
|
|
|
|
/// Discussion of this unsafety on Unix may be found in:
|
|
|
|
|
///
|
2021-06-23 20:26:46 +00:00
|
|
|
|
/// - [Austin Group Bugzilla](https://austingroupbugs.net/view.php?id=188)
|
2015-04-23 20:59:36 +00:00
|
|
|
|
/// - [GNU C library Bugzilla](https://sourceware.org/bugzilla/show_bug.cgi?id=15607#c2)
|
|
|
|
|
///
|
2015-10-25 12:04:29 +00:00
|
|
|
|
/// # Panics
|
|
|
|
|
///
|
2021-07-23 05:32:55 +00:00
|
|
|
|
/// This function may panic if `key` is empty, contains an ASCII equals sign `'='`
|
|
|
|
|
/// or the NUL character `'\0'`, or when `value` contains the NUL character.
|
2015-10-25 12:04:29 +00:00
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
|
|
|
|
/// let key = "KEY";
|
|
|
|
|
/// env::set_var(key, "VALUE");
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// assert_eq!(env::var(key), Ok("VALUE".to_string()));
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// ```
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2021-05-10 11:31:09 +00:00
|
|
|
|
pub fn set_var<K: AsRef<OsStr>, V: AsRef<OsStr>>(key: K, value: V) {
|
|
|
|
|
_set_var(key.as_ref(), value.as_ref())
|
2015-09-09 19:37:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-10 11:31:09 +00:00
|
|
|
|
fn _set_var(key: &OsStr, value: &OsStr) {
|
|
|
|
|
os_imp::setenv(key, value).unwrap_or_else(|e| {
|
2022-02-12 19:16:17 +00:00
|
|
|
|
panic!("failed to set environment variable `{key:?}` to `{value:?}`: {e}")
|
2015-10-25 17:19:35 +00:00
|
|
|
|
})
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-13 14:21:32 +00:00
|
|
|
|
/// Removes an environment variable from the environment of the currently running process.
|
2015-03-31 04:19:31 +00:00
|
|
|
|
///
|
2015-04-23 20:59:36 +00:00
|
|
|
|
/// Note that while concurrent access to environment variables is safe in Rust,
|
|
|
|
|
/// some platforms only expose inherently unsafe non-threadsafe APIs for
|
|
|
|
|
/// inspecting the environment. As a result extra care needs to be taken when
|
|
|
|
|
/// auditing calls to unsafe external FFI functions to ensure that any external
|
|
|
|
|
/// environment accesses are properly synchronized with accesses in Rust.
|
|
|
|
|
///
|
|
|
|
|
/// Discussion of this unsafety on Unix may be found in:
|
|
|
|
|
///
|
2021-06-23 20:26:46 +00:00
|
|
|
|
/// - [Austin Group Bugzilla](https://austingroupbugs.net/view.php?id=188)
|
2015-04-23 20:59:36 +00:00
|
|
|
|
/// - [GNU C library Bugzilla](https://sourceware.org/bugzilla/show_bug.cgi?id=15607#c2)
|
|
|
|
|
///
|
2015-10-25 12:04:29 +00:00
|
|
|
|
/// # Panics
|
|
|
|
|
///
|
2015-10-25 20:03:42 +00:00
|
|
|
|
/// This function may panic if `key` is empty, contains an ASCII equals sign
|
|
|
|
|
/// `'='` or the NUL character `'\0'`, or when the value contains the NUL
|
|
|
|
|
/// character.
|
2015-10-25 12:04:29 +00:00
|
|
|
|
///
|
2015-03-31 04:19:31 +00:00
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
|
|
|
|
/// let key = "KEY";
|
|
|
|
|
/// env::set_var(key, "VALUE");
|
|
|
|
|
/// assert_eq!(env::var(key), Ok("VALUE".to_string()));
|
|
|
|
|
///
|
|
|
|
|
/// env::remove_var(key);
|
|
|
|
|
/// assert!(env::var(key).is_err());
|
|
|
|
|
/// ```
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2021-05-10 11:31:09 +00:00
|
|
|
|
pub fn remove_var<K: AsRef<OsStr>>(key: K) {
|
|
|
|
|
_remove_var(key.as_ref())
|
2015-09-09 19:37:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-10 11:31:09 +00:00
|
|
|
|
fn _remove_var(key: &OsStr) {
|
|
|
|
|
os_imp::unsetenv(key)
|
2022-02-12 19:16:17 +00:00
|
|
|
|
.unwrap_or_else(|e| panic!("failed to remove environment variable `{key:?}`: {e}"))
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-18 08:26:47 +00:00
|
|
|
|
/// An iterator that splits an environment variable into paths according to
|
|
|
|
|
/// platform-specific conventions.
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2019-04-16 21:37:07 +00:00
|
|
|
|
/// The iterator element type is [`PathBuf`].
|
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// This structure is created by [`env::split_paths()`]. See its
|
2017-05-18 08:26:47 +00:00
|
|
|
|
/// documentation for more.
|
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// [`env::split_paths()`]: split_paths
|
2021-10-31 02:58:27 +00:00
|
|
|
|
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2019-11-27 18:29:00 +00:00
|
|
|
|
pub struct SplitPaths<'a> {
|
|
|
|
|
inner: os_imp::SplitPaths<'a>,
|
|
|
|
|
}
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
|
|
|
|
/// Parses input according to platform conventions for the `PATH`
|
|
|
|
|
/// environment variable.
|
|
|
|
|
///
|
2019-04-16 21:37:07 +00:00
|
|
|
|
/// Returns an iterator over the paths contained in `unparsed`. The iterator
|
|
|
|
|
/// element type is [`PathBuf`].
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
|
|
|
|
/// let key = "PATH";
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// match env::var_os(key) {
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// Some(paths) => {
|
|
|
|
|
/// for path in env::split_paths(&paths) {
|
|
|
|
|
/// println!("'{}'", path.display());
|
|
|
|
|
/// }
|
|
|
|
|
/// }
|
2022-02-12 19:16:17 +00:00
|
|
|
|
/// None => println!("{key} is not defined in the environment.")
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2019-03-01 08:34:11 +00:00
|
|
|
|
pub fn split_paths<T: AsRef<OsStr> + ?Sized>(unparsed: &T) -> SplitPaths<'_> {
|
2015-03-30 18:00:05 +00:00
|
|
|
|
SplitPaths { inner: os_imp::split_paths(unparsed.as_ref()) }
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
impl<'a> Iterator for SplitPaths<'a> {
|
2015-02-23 18:59:17 +00:00
|
|
|
|
type Item = PathBuf;
|
2019-11-27 18:29:00 +00:00
|
|
|
|
fn next(&mut self) -> Option<PathBuf> {
|
|
|
|
|
self.inner.next()
|
|
|
|
|
}
|
|
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
|
|
|
self.inner.size_hint()
|
|
|
|
|
}
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-29 13:31:47 +00:00
|
|
|
|
#[stable(feature = "std_debug", since = "1.16.0")]
|
2019-02-18 03:42:36 +00:00
|
|
|
|
impl fmt::Debug for SplitPaths<'_> {
|
2019-03-01 08:34:11 +00:00
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2021-04-05 11:31:11 +00:00
|
|
|
|
f.debug_struct("SplitPaths").finish_non_exhaustive()
|
2016-11-25 18:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-18 08:26:47 +00:00
|
|
|
|
/// The error type for operations on the `PATH` variable. Possibly returned from
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// [`env::join_paths()`].
|
2017-05-18 08:26:47 +00:00
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// [`env::join_paths()`]: join_paths
|
2015-01-27 20:20:58 +00:00
|
|
|
|
#[derive(Debug)]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
pub struct JoinPathsError {
|
2019-11-27 18:29:00 +00:00
|
|
|
|
inner: os_imp::JoinPathsError,
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-08 17:42:01 +00:00
|
|
|
|
/// Joins a collection of [`Path`]s appropriately for the `PATH`
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// environment variable.
|
|
|
|
|
///
|
2017-05-18 08:26:47 +00:00
|
|
|
|
/// # Errors
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2020-08-17 13:42:23 +00:00
|
|
|
|
/// Returns an [`Err`] (containing an error message) if one of the input
|
2017-02-08 17:42:01 +00:00
|
|
|
|
/// [`Path`]s contains an invalid character for constructing the `PATH`
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// variable (a double quote on Windows or a colon on Unix).
|
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2017-06-19 02:21:17 +00:00
|
|
|
|
/// Joining paths on a Unix-like platform:
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// use std::env;
|
|
|
|
|
/// use std::ffi::OsString;
|
|
|
|
|
/// use std::path::Path;
|
|
|
|
|
///
|
2018-05-14 02:32:27 +00:00
|
|
|
|
/// fn main() -> Result<(), env::JoinPathsError> {
|
|
|
|
|
/// # if cfg!(unix) {
|
|
|
|
|
/// let paths = [Path::new("/bin"), Path::new("/usr/bin")];
|
|
|
|
|
/// let path_os_string = env::join_paths(paths.iter())?;
|
|
|
|
|
/// assert_eq!(path_os_string, OsString::from("/bin:/usr/bin"));
|
2017-06-19 02:21:17 +00:00
|
|
|
|
/// # }
|
2018-05-14 02:32:27 +00:00
|
|
|
|
/// Ok(())
|
|
|
|
|
/// }
|
2017-06-19 02:21:17 +00:00
|
|
|
|
/// ```
|
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// Joining a path containing a colon on a Unix-like platform results in an
|
|
|
|
|
/// error:
|
2017-06-19 02:21:17 +00:00
|
|
|
|
///
|
|
|
|
|
/// ```
|
|
|
|
|
/// # if cfg!(unix) {
|
|
|
|
|
/// use std::env;
|
|
|
|
|
/// use std::path::Path;
|
|
|
|
|
///
|
|
|
|
|
/// let paths = [Path::new("/bin"), Path::new("/usr/bi:n")];
|
|
|
|
|
/// assert!(env::join_paths(paths.iter()).is_err());
|
|
|
|
|
/// # }
|
|
|
|
|
/// ```
|
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// Using `env::join_paths()` with [`env::split_paths()`] to append an item to
|
|
|
|
|
/// the `PATH` environment variable:
|
2017-06-19 02:21:17 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// use std::env;
|
2015-02-23 18:59:17 +00:00
|
|
|
|
/// use std::path::PathBuf;
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2018-05-14 02:32:27 +00:00
|
|
|
|
/// fn main() -> Result<(), env::JoinPathsError> {
|
|
|
|
|
/// if let Some(path) = env::var_os("PATH") {
|
|
|
|
|
/// let mut paths = env::split_paths(&path).collect::<Vec<_>>();
|
|
|
|
|
/// paths.push(PathBuf::from("/home/xyz/bin"));
|
|
|
|
|
/// let new_path = env::join_paths(paths)?;
|
|
|
|
|
/// env::set_var("PATH", &new_path);
|
|
|
|
|
/// }
|
|
|
|
|
///
|
|
|
|
|
/// Ok(())
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2019-05-24 01:35:27 +00:00
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// [`env::split_paths()`]: split_paths
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError>
|
2019-11-27 18:29:00 +00:00
|
|
|
|
where
|
|
|
|
|
I: IntoIterator<Item = T>,
|
|
|
|
|
T: AsRef<OsStr>,
|
2015-01-27 20:20:58 +00:00
|
|
|
|
{
|
2019-11-27 18:29:00 +00:00
|
|
|
|
os_imp::join_paths(paths.into_iter()).map_err(|e| JoinPathsError { inner: e })
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
impl fmt::Display for JoinPathsError {
|
2019-03-01 08:34:11 +00:00
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2015-01-27 20:20:58 +00:00
|
|
|
|
self.inner.fmt(f)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
impl Error for JoinPathsError {
|
2019-12-01 04:01:48 +00:00
|
|
|
|
#[allow(deprecated, deprecated_in_future)]
|
2019-11-27 18:29:00 +00:00
|
|
|
|
fn description(&self) -> &str {
|
|
|
|
|
self.inner.description()
|
|
|
|
|
}
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 07:01:21 +00:00
|
|
|
|
/// Returns the path of the current user's home directory if known.
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
|
|
|
|
/// # Unix
|
|
|
|
|
///
|
2018-07-05 15:32:09 +00:00
|
|
|
|
/// - Returns the value of the 'HOME' environment variable if it is set
|
|
|
|
|
/// (including to an empty string).
|
|
|
|
|
/// - Otherwise, it tries to determine the home directory by invoking the `getpwuid_r` function
|
|
|
|
|
/// using the UID of the current user. An empty home directory field returned from the
|
|
|
|
|
/// `getpwuid_r` function is considered to be a valid value.
|
|
|
|
|
/// - Returns `None` if the current user has no entry in the /etc/passwd file.
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
|
|
|
|
/// # Windows
|
|
|
|
|
///
|
2018-07-05 15:32:09 +00:00
|
|
|
|
/// - Returns the value of the 'HOME' environment variable if it is set
|
|
|
|
|
/// (including to an empty string).
|
|
|
|
|
/// - Otherwise, returns the value of the 'USERPROFILE' environment variable if it is set
|
|
|
|
|
/// (including to an empty string).
|
|
|
|
|
/// - If both do not exist, [`GetUserProfileDirectory`][msdn] is used to return the path.
|
2015-10-10 18:50:26 +00:00
|
|
|
|
///
|
2019-12-25 15:35:54 +00:00
|
|
|
|
/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectorya
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2022-09-10 11:43:30 +00:00
|
|
|
|
/// # Deprecation
|
|
|
|
|
///
|
|
|
|
|
/// This function is deprecated because the behaviour on Windows is not correct.
|
2022-10-03 16:27:13 +00:00
|
|
|
|
/// The 'HOME' environment variable is not standard on Windows, and may not produce
|
|
|
|
|
/// desired results; for instance, under Cygwin or Mingw it will return `/home/you`
|
2022-09-10 11:43:30 +00:00
|
|
|
|
/// when it should return `C:\Users\you`.
|
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
|
|
|
|
/// match env::home_dir() {
|
2018-07-05 15:32:09 +00:00
|
|
|
|
/// Some(path) => println!("Your home directory, probably: {}", path.display()),
|
2016-02-25 21:19:47 +00:00
|
|
|
|
/// None => println!("Impossible to get your home dir!"),
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2022-04-08 01:20:32 +00:00
|
|
|
|
#[deprecated(
|
2019-11-27 18:29:00 +00:00
|
|
|
|
since = "1.29.0",
|
2022-09-10 11:43:30 +00:00
|
|
|
|
note = "This function's behavior may be unexpected on Windows. \
|
2022-04-08 01:20:32 +00:00
|
|
|
|
Consider using a crate from crates.io instead."
|
2019-11-27 18:29:00 +00:00
|
|
|
|
)]
|
2021-10-31 02:58:27 +00:00
|
|
|
|
#[must_use]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-02-23 18:59:17 +00:00
|
|
|
|
pub fn home_dir() -> Option<PathBuf> {
|
2015-01-27 20:20:58 +00:00
|
|
|
|
os_imp::home_dir()
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 07:01:21 +00:00
|
|
|
|
/// Returns the path of a temporary directory.
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2021-01-20 19:24:47 +00:00
|
|
|
|
/// The temporary directory may be shared among users, or between processes
|
|
|
|
|
/// with different privileges; thus, the creation of any files or directories
|
|
|
|
|
/// in the temporary directory must use a secure method to create a uniquely
|
|
|
|
|
/// named file. Creating a file or directory with a fixed or predictable name
|
|
|
|
|
/// may result in "insecure temporary file" security vulnerabilities. Consider
|
|
|
|
|
/// using a crate that securely creates temporary files or directories.
|
|
|
|
|
///
|
2021-10-17 04:23:42 +00:00
|
|
|
|
/// # Platform-specific behavior
|
2017-05-18 08:26:47 +00:00
|
|
|
|
///
|
2021-10-17 04:23:42 +00:00
|
|
|
|
/// On Unix, returns the value of the `TMPDIR` environment variable if it is
|
2022-09-28 19:51:09 +00:00
|
|
|
|
/// set, otherwise for non-Android it returns `/tmp`. On Android, since there
|
2016-05-12 04:05:25 +00:00
|
|
|
|
/// is no global temporary folder (it is usually allocated per-app), it returns
|
|
|
|
|
/// `/data/local/tmp`.
|
2021-10-17 04:23:42 +00:00
|
|
|
|
/// On Windows, the behavior is equivalent to that of [`GetTempPath2`][GetTempPath2] /
|
|
|
|
|
/// [`GetTempPath`][GetTempPath], which this function uses internally.
|
|
|
|
|
/// Note that, this [may change in the future][changes].
|
2016-05-12 04:05:25 +00:00
|
|
|
|
///
|
2021-10-17 04:23:42 +00:00
|
|
|
|
/// [changes]: io#platform-specific-behavior
|
|
|
|
|
/// [GetTempPath2]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a
|
|
|
|
|
/// [GetTempPath]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppatha
|
2015-03-31 04:19:31 +00:00
|
|
|
|
///
|
2018-03-25 02:56:07 +00:00
|
|
|
|
/// ```no_run
|
2015-03-31 04:19:31 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
2021-01-20 19:24:47 +00:00
|
|
|
|
/// fn main() {
|
2021-10-17 04:23:42 +00:00
|
|
|
|
/// let dir = env::temp_dir();
|
2021-01-20 19:24:47 +00:00
|
|
|
|
/// println!("Temporary directory: {}", dir.display());
|
2018-03-25 02:56:07 +00:00
|
|
|
|
/// }
|
2015-03-31 04:19:31 +00:00
|
|
|
|
/// ```
|
2021-10-31 02:58:27 +00:00
|
|
|
|
#[must_use]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-02-23 18:59:17 +00:00
|
|
|
|
pub fn temp_dir() -> PathBuf {
|
2015-01-27 20:20:58 +00:00
|
|
|
|
os_imp::temp_dir()
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 07:01:21 +00:00
|
|
|
|
/// Returns the full filesystem path of the current running executable.
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2017-12-24 19:29:13 +00:00
|
|
|
|
/// # Platform-specific behavior
|
|
|
|
|
///
|
|
|
|
|
/// If the executable was invoked through a symbolic link, some platforms will
|
|
|
|
|
/// return the path of the symbolic link and other platforms will return the
|
|
|
|
|
/// path of the symbolic link’s target.
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2021-08-27 13:25:29 +00:00
|
|
|
|
/// If the executable is renamed while it is running, platforms may return the
|
|
|
|
|
/// path at the time it was loaded instead of the new path.
|
|
|
|
|
///
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// # Errors
|
|
|
|
|
///
|
2016-03-30 07:01:21 +00:00
|
|
|
|
/// Acquiring the path of the current executable is a platform-specific operation
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// that can fail for a good number of reasons. Some errors can include, but not
|
2016-02-25 20:52:02 +00:00
|
|
|
|
/// be limited to, filesystem operations failing or general syscall failures.
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2016-05-09 23:45:12 +00:00
|
|
|
|
/// # Security
|
|
|
|
|
///
|
2022-05-03 12:23:28 +00:00
|
|
|
|
/// The output of this function should not be trusted for anything
|
|
|
|
|
/// that might have security implications. Basically, if users can run
|
|
|
|
|
/// the executable, they can change the output arbitrarily.
|
|
|
|
|
///
|
|
|
|
|
/// As an example, you can easily introduce a race condition. It goes
|
|
|
|
|
/// like this:
|
|
|
|
|
///
|
|
|
|
|
/// 1. You get the path to the current executable using `current_exe()`, and
|
|
|
|
|
/// store it in a variable.
|
|
|
|
|
/// 2. Time passes. A malicious actor removes the current executable, and
|
|
|
|
|
/// replaces it with a malicious one.
|
|
|
|
|
/// 3. You then use the stored path to re-execute the current
|
|
|
|
|
/// executable.
|
|
|
|
|
///
|
|
|
|
|
/// You expected to safely execute the current executable, but you're
|
|
|
|
|
/// instead executing something completely different. The code you
|
|
|
|
|
/// just executed run with your privileges.
|
2016-07-19 16:32:56 +00:00
|
|
|
|
///
|
2016-07-20 20:43:53 +00:00
|
|
|
|
/// This sort of behavior has been known to [lead to privilege escalation] when
|
2017-12-24 19:29:13 +00:00
|
|
|
|
/// used incorrectly.
|
2016-07-19 16:32:56 +00:00
|
|
|
|
///
|
2017-12-24 19:29:13 +00:00
|
|
|
|
/// [lead to privilege escalation]: https://securityvulns.com/Wdocument183.html
|
2016-05-09 23:45:12 +00:00
|
|
|
|
///
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// # Examples
|
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
|
|
|
|
/// match env::current_exe() {
|
|
|
|
|
/// Ok(exe_path) => println!("Path of this executable is: {}",
|
2017-12-24 19:29:13 +00:00
|
|
|
|
/// exe_path.display()),
|
2022-02-12 19:16:17 +00:00
|
|
|
|
/// Err(e) => println!("failed to get current exe path: {e}"),
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// };
|
|
|
|
|
/// ```
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-02-23 18:59:17 +00:00
|
|
|
|
pub fn current_exe() -> io::Result<PathBuf> {
|
2015-01-27 20:20:58 +00:00
|
|
|
|
os_imp::current_exe()
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-10 06:19:28 +00:00
|
|
|
|
/// An iterator over the arguments of a process, yielding a [`String`] value for
|
|
|
|
|
/// each argument.
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// This struct is created by [`env::args()`]. See its documentation
|
|
|
|
|
/// for more.
|
2016-11-21 22:12:14 +00:00
|
|
|
|
///
|
2017-03-05 21:39:24 +00:00
|
|
|
|
/// The first element is traditionally the path of the executable, but it can be
|
2021-07-23 23:14:28 +00:00
|
|
|
|
/// set to arbitrary text, and might not even exist. This means this property
|
2017-06-10 06:19:28 +00:00
|
|
|
|
/// should not be relied upon for security purposes.
|
2017-03-05 21:39:24 +00:00
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// [`env::args()`]: args
|
2021-10-31 02:58:27 +00:00
|
|
|
|
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2019-11-27 18:29:00 +00:00
|
|
|
|
pub struct Args {
|
|
|
|
|
inner: ArgsOs,
|
|
|
|
|
}
|
2015-02-11 19:47:53 +00:00
|
|
|
|
|
2016-11-21 22:12:14 +00:00
|
|
|
|
/// An iterator over the arguments of a process, yielding an [`OsString`] value
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// for each argument.
|
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// This struct is created by [`env::args_os()`]. See its documentation
|
|
|
|
|
/// for more.
|
2016-11-21 22:12:14 +00:00
|
|
|
|
///
|
2017-03-05 21:39:24 +00:00
|
|
|
|
/// The first element is traditionally the path of the executable, but it can be
|
2021-07-23 23:14:28 +00:00
|
|
|
|
/// set to arbitrary text, and might not even exist. This means this property
|
2017-06-10 06:19:28 +00:00
|
|
|
|
/// should not be relied upon for security purposes.
|
2017-03-05 21:39:24 +00:00
|
|
|
|
///
|
2020-08-26 14:30:54 +00:00
|
|
|
|
/// [`env::args_os()`]: args_os
|
2021-10-31 02:58:27 +00:00
|
|
|
|
#[must_use = "iterators are lazy and do nothing unless consumed"]
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2019-11-27 18:29:00 +00:00
|
|
|
|
pub struct ArgsOs {
|
|
|
|
|
inner: sys::args::Args,
|
|
|
|
|
}
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
2020-09-04 21:00:09 +00:00
|
|
|
|
/// Returns the arguments that this program was started with (normally passed
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// via the command line).
|
|
|
|
|
///
|
2016-03-30 07:01:21 +00:00
|
|
|
|
/// The first element is traditionally the path of the executable, but it can be
|
2021-07-23 23:14:28 +00:00
|
|
|
|
/// set to arbitrary text, and might not even exist. This means this property should
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// not be relied upon for security purposes.
|
|
|
|
|
///
|
2020-09-04 21:00:09 +00:00
|
|
|
|
/// On Unix systems the shell usually expands unquoted arguments with glob patterns
|
2017-11-07 12:17:04 +00:00
|
|
|
|
/// (such as `*` and `?`). On Windows this is not done, and such arguments are
|
|
|
|
|
/// passed as-is.
|
|
|
|
|
///
|
2020-09-04 21:00:09 +00:00
|
|
|
|
/// On glibc Linux systems, arguments are retrieved by placing a function in `.init_array`.
|
2021-04-25 12:45:48 +00:00
|
|
|
|
/// glibc passes `argc`, `argv`, and `envp` to functions in `.init_array`, as a non-standard
|
2020-09-04 21:00:09 +00:00
|
|
|
|
/// extension. This allows `std::env::args` to work even in a `cdylib` or `staticlib`, as it
|
|
|
|
|
/// does on macOS and Windows.
|
2019-11-21 18:34:31 +00:00
|
|
|
|
///
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// # Panics
|
|
|
|
|
///
|
|
|
|
|
/// The returned iterator will panic during iteration if any argument to the
|
2021-04-25 12:45:48 +00:00
|
|
|
|
/// process is not valid Unicode. If this is not desired,
|
2016-11-21 22:12:14 +00:00
|
|
|
|
/// use the [`args_os`] function instead.
|
2015-02-11 19:47:53 +00:00
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-01-27 20:20:58 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
|
|
|
|
/// // Prints each argument on a separate line
|
|
|
|
|
/// for argument in env::args() {
|
2022-02-12 19:16:17 +00:00
|
|
|
|
/// println!("{argument}");
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
pub fn args() -> Args {
|
2015-02-11 19:47:53 +00:00
|
|
|
|
Args { inner: args_os() }
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-25 12:45:48 +00:00
|
|
|
|
/// Returns the arguments that this program was started with (normally passed
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// via the command line).
|
|
|
|
|
///
|
2016-03-30 07:01:21 +00:00
|
|
|
|
/// The first element is traditionally the path of the executable, but it can be
|
2021-07-23 23:14:28 +00:00
|
|
|
|
/// set to arbitrary text, and might not even exist. This means this property should
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// not be relied upon for security purposes.
|
|
|
|
|
///
|
2021-04-25 12:45:48 +00:00
|
|
|
|
/// On Unix systems the shell usually expands unquoted arguments with glob patterns
|
|
|
|
|
/// (such as `*` and `?`). On Windows this is not done, and such arguments are
|
|
|
|
|
/// passed as-is.
|
|
|
|
|
///
|
|
|
|
|
/// On glibc Linux systems, arguments are retrieved by placing a function in `.init_array`.
|
|
|
|
|
/// glibc passes `argc`, `argv`, and `envp` to functions in `.init_array`, as a non-standard
|
|
|
|
|
/// extension. This allows `std::env::args_os` to work even in a `cdylib` or `staticlib`, as it
|
|
|
|
|
/// does on macOS and Windows.
|
|
|
|
|
///
|
2021-04-25 13:48:24 +00:00
|
|
|
|
/// Note that the returned iterator will not check if the arguments to the
|
2021-04-27 19:31:04 +00:00
|
|
|
|
/// process are valid Unicode. If you want to panic on invalid UTF-8,
|
2021-04-25 12:45:48 +00:00
|
|
|
|
/// use the [`args`] function instead.
|
2019-11-21 18:34:31 +00:00
|
|
|
|
///
|
2015-03-12 01:11:40 +00:00
|
|
|
|
/// # Examples
|
2015-02-11 19:47:53 +00:00
|
|
|
|
///
|
2015-03-13 02:42:38 +00:00
|
|
|
|
/// ```
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// use std::env;
|
|
|
|
|
///
|
|
|
|
|
/// // Prints each argument on a separate line
|
|
|
|
|
/// for argument in env::args_os() {
|
2022-02-12 19:16:17 +00:00
|
|
|
|
/// println!("{argument:?}");
|
2015-02-11 19:47:53 +00:00
|
|
|
|
/// }
|
|
|
|
|
/// ```
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-02-11 19:47:53 +00:00
|
|
|
|
pub fn args_os() -> ArgsOs {
|
2016-09-29 22:00:44 +00:00
|
|
|
|
ArgsOs { inner: sys::args::args() }
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 23:35:09 +00:00
|
|
|
|
#[stable(feature = "env_unimpl_send_sync", since = "1.26.0")]
|
2018-02-04 19:40:39 +00:00
|
|
|
|
impl !Send for Args {}
|
|
|
|
|
|
2018-04-04 23:35:09 +00:00
|
|
|
|
#[stable(feature = "env_unimpl_send_sync", since = "1.26.0")]
|
2018-02-04 19:40:39 +00:00
|
|
|
|
impl !Sync for Args {}
|
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
impl Iterator for Args {
|
2015-02-11 19:47:53 +00:00
|
|
|
|
type Item = String;
|
|
|
|
|
fn next(&mut self) -> Option<String> {
|
|
|
|
|
self.inner.next().map(|s| s.into_string().unwrap())
|
|
|
|
|
}
|
2019-11-27 18:29:00 +00:00
|
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
|
|
|
self.inner.size_hint()
|
|
|
|
|
}
|
2015-02-11 19:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-02-16 10:15:30 +00:00
|
|
|
|
impl ExactSizeIterator for Args {
|
2019-11-27 18:29:00 +00:00
|
|
|
|
fn len(&self) -> usize {
|
|
|
|
|
self.inner.len()
|
|
|
|
|
}
|
|
|
|
|
fn is_empty(&self) -> bool {
|
|
|
|
|
self.inner.is_empty()
|
|
|
|
|
}
|
2015-02-16 10:15:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 07:38:39 +00:00
|
|
|
|
#[stable(feature = "env_iterators", since = "1.12.0")]
|
2016-04-30 14:37:44 +00:00
|
|
|
|
impl DoubleEndedIterator for Args {
|
|
|
|
|
fn next_back(&mut self) -> Option<String> {
|
|
|
|
|
self.inner.next_back().map(|s| s.into_string().unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-29 13:31:47 +00:00
|
|
|
|
#[stable(feature = "std_debug", since = "1.16.0")]
|
2016-11-25 18:21:49 +00:00
|
|
|
|
impl fmt::Debug for Args {
|
2019-03-01 08:34:11 +00:00
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2021-04-21 21:51:28 +00:00
|
|
|
|
f.debug_struct("Args").field("inner", &self.inner.inner).finish()
|
2016-11-25 18:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 23:35:09 +00:00
|
|
|
|
#[stable(feature = "env_unimpl_send_sync", since = "1.26.0")]
|
2018-02-04 19:40:39 +00:00
|
|
|
|
impl !Send for ArgsOs {}
|
|
|
|
|
|
2018-04-04 23:35:09 +00:00
|
|
|
|
#[stable(feature = "env_unimpl_send_sync", since = "1.26.0")]
|
2018-02-04 19:40:39 +00:00
|
|
|
|
impl !Sync for ArgsOs {}
|
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-02-11 19:47:53 +00:00
|
|
|
|
impl Iterator for ArgsOs {
|
2015-01-27 20:20:58 +00:00
|
|
|
|
type Item = OsString;
|
2019-11-27 18:29:00 +00:00
|
|
|
|
fn next(&mut self) -> Option<OsString> {
|
|
|
|
|
self.inner.next()
|
|
|
|
|
}
|
|
|
|
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
|
|
|
|
self.inner.size_hint()
|
|
|
|
|
}
|
2015-01-27 20:20:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-02-16 10:15:30 +00:00
|
|
|
|
impl ExactSizeIterator for ArgsOs {
|
2019-11-27 18:29:00 +00:00
|
|
|
|
fn len(&self) -> usize {
|
|
|
|
|
self.inner.len()
|
|
|
|
|
}
|
|
|
|
|
fn is_empty(&self) -> bool {
|
|
|
|
|
self.inner.is_empty()
|
|
|
|
|
}
|
2015-02-16 10:15:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 07:38:39 +00:00
|
|
|
|
#[stable(feature = "env_iterators", since = "1.12.0")]
|
2016-04-30 14:37:44 +00:00
|
|
|
|
impl DoubleEndedIterator for ArgsOs {
|
2019-11-27 18:29:00 +00:00
|
|
|
|
fn next_back(&mut self) -> Option<OsString> {
|
|
|
|
|
self.inner.next_back()
|
|
|
|
|
}
|
2016-04-30 14:37:44 +00:00
|
|
|
|
}
|
2016-11-25 18:21:49 +00:00
|
|
|
|
|
2017-01-29 13:31:47 +00:00
|
|
|
|
#[stable(feature = "std_debug", since = "1.16.0")]
|
2016-11-25 18:21:49 +00:00
|
|
|
|
impl fmt::Debug for ArgsOs {
|
2019-03-01 08:34:11 +00:00
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2021-04-21 21:51:28 +00:00
|
|
|
|
f.debug_struct("ArgsOs").field("inner", &self.inner).finish()
|
2016-11-25 18:21:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-27 20:20:58 +00:00
|
|
|
|
/// Constants associated with the current target
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2015-01-27 20:20:58 +00:00
|
|
|
|
pub mod consts {
|
2019-02-10 19:23:21 +00:00
|
|
|
|
use crate::sys::env::os;
|
2016-09-21 19:50:30 +00:00
|
|
|
|
|
2016-02-18 20:46:03 +00:00
|
|
|
|
/// A string describing the architecture of the CPU that is currently
|
2015-02-27 18:59:59 +00:00
|
|
|
|
/// in use.
|
2015-05-21 03:19:55 +00:00
|
|
|
|
///
|
|
|
|
|
/// Some possible values:
|
|
|
|
|
///
|
|
|
|
|
/// - x86
|
|
|
|
|
/// - x86_64
|
|
|
|
|
/// - arm
|
|
|
|
|
/// - aarch64
|
2021-08-25 07:51:34 +00:00
|
|
|
|
/// - m68k
|
2015-05-21 03:19:55 +00:00
|
|
|
|
/// - mips
|
2016-08-27 06:39:29 +00:00
|
|
|
|
/// - mips64
|
2015-05-21 03:19:55 +00:00
|
|
|
|
/// - powerpc
|
2015-12-28 21:09:06 +00:00
|
|
|
|
/// - powerpc64
|
2019-11-23 07:22:05 +00:00
|
|
|
|
/// - riscv64
|
2016-09-09 21:00:23 +00:00
|
|
|
|
/// - s390x
|
2016-12-06 21:57:43 +00:00
|
|
|
|
/// - sparc64
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2020-05-21 23:43:59 +00:00
|
|
|
|
pub const ARCH: &str = env!("STD_ENV_ARCH");
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
2016-04-05 15:55:14 +00:00
|
|
|
|
/// The family of the operating system. Example value is `unix`.
|
2015-05-21 03:19:55 +00:00
|
|
|
|
///
|
|
|
|
|
/// Some possible values:
|
|
|
|
|
///
|
|
|
|
|
/// - unix
|
|
|
|
|
/// - windows
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2018-12-04 09:21:42 +00:00
|
|
|
|
pub const FAMILY: &str = os::FAMILY;
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
2016-04-05 15:55:14 +00:00
|
|
|
|
/// A string describing the specific operating system in use.
|
|
|
|
|
/// Example value is `linux`.
|
2015-05-21 03:19:55 +00:00
|
|
|
|
///
|
|
|
|
|
/// Some possible values:
|
|
|
|
|
///
|
|
|
|
|
/// - linux
|
|
|
|
|
/// - macos
|
|
|
|
|
/// - ios
|
|
|
|
|
/// - freebsd
|
|
|
|
|
/// - dragonfly
|
2015-07-01 03:37:11 +00:00
|
|
|
|
/// - netbsd
|
2015-05-21 03:19:55 +00:00
|
|
|
|
/// - openbsd
|
2016-01-28 11:02:31 +00:00
|
|
|
|
/// - solaris
|
2015-05-21 03:19:55 +00:00
|
|
|
|
/// - android
|
|
|
|
|
/// - windows
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2018-12-04 09:21:42 +00:00
|
|
|
|
pub const OS: &str = os::OS;
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
|
|
|
|
/// Specifies the filename prefix used for shared libraries on this
|
2016-04-05 15:55:14 +00:00
|
|
|
|
/// platform. Example value is `lib`.
|
2015-05-21 03:19:55 +00:00
|
|
|
|
///
|
|
|
|
|
/// Some possible values:
|
|
|
|
|
///
|
|
|
|
|
/// - lib
|
|
|
|
|
/// - `""` (an empty string)
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2018-12-04 09:21:42 +00:00
|
|
|
|
pub const DLL_PREFIX: &str = os::DLL_PREFIX;
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
|
|
|
|
/// Specifies the filename suffix used for shared libraries on this
|
2016-04-05 15:55:14 +00:00
|
|
|
|
/// platform. Example value is `.so`.
|
2015-05-21 03:19:55 +00:00
|
|
|
|
///
|
|
|
|
|
/// Some possible values:
|
|
|
|
|
///
|
|
|
|
|
/// - .so
|
|
|
|
|
/// - .dylib
|
|
|
|
|
/// - .dll
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2018-12-04 09:21:42 +00:00
|
|
|
|
pub const DLL_SUFFIX: &str = os::DLL_SUFFIX;
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
|
|
|
|
/// Specifies the file extension used for shared libraries on this
|
2016-04-05 15:55:14 +00:00
|
|
|
|
/// platform that goes after the dot. Example value is `so`.
|
2015-05-21 03:19:55 +00:00
|
|
|
|
///
|
|
|
|
|
/// Some possible values:
|
|
|
|
|
///
|
2015-12-01 21:53:48 +00:00
|
|
|
|
/// - so
|
|
|
|
|
/// - dylib
|
|
|
|
|
/// - dll
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2018-12-04 09:21:42 +00:00
|
|
|
|
pub const DLL_EXTENSION: &str = os::DLL_EXTENSION;
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
|
|
|
|
/// Specifies the filename suffix used for executable binaries on this
|
2016-04-05 15:55:14 +00:00
|
|
|
|
/// platform. Example value is `.exe`.
|
2015-05-21 03:19:55 +00:00
|
|
|
|
///
|
|
|
|
|
/// Some possible values:
|
|
|
|
|
///
|
2015-12-01 21:53:48 +00:00
|
|
|
|
/// - .exe
|
|
|
|
|
/// - .nexe
|
|
|
|
|
/// - .pexe
|
2015-05-21 03:19:55 +00:00
|
|
|
|
/// - `""` (an empty string)
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2018-12-04 09:21:42 +00:00
|
|
|
|
pub const EXE_SUFFIX: &str = os::EXE_SUFFIX;
|
2015-01-27 20:20:58 +00:00
|
|
|
|
|
|
|
|
|
/// Specifies the file extension, if any, used for executable binaries
|
2016-04-05 15:55:14 +00:00
|
|
|
|
/// on this platform. Example value is `exe`.
|
2015-05-21 03:19:55 +00:00
|
|
|
|
///
|
|
|
|
|
/// Some possible values:
|
|
|
|
|
///
|
|
|
|
|
/// - exe
|
|
|
|
|
/// - `""` (an empty string)
|
2015-02-27 18:59:59 +00:00
|
|
|
|
#[stable(feature = "env", since = "1.0.0")]
|
2018-12-04 09:21:42 +00:00
|
|
|
|
pub const EXE_EXTENSION: &str = os::EXE_EXTENSION;
|
2016-09-25 04:38:56 +00:00
|
|
|
|
}
|