Rollup merge of #153623 - joboet:move_pal_os, r=Mark-Simulacrum

std: move `sys::pal::os` to `sys::paths`

Part of rust-lang/rust#117276.

After rust-lang/rust#150723, rust-lang/rust#153130, rust-lang/rust#153341 and rust-lang/rust#153413, `sys::pal::os` only contains default-path related functions (like `getcwd` and the `PATH`-splitting logic). In line with rust-lang/rust#117276, this PR thus moves all these implementations into a new module in `sys`: `sys::paths`.

~There is one functional change here: The `chdir` implementation on SGX used to use `sgx_ineffective` which silently fails, but now returns an error unconditionally – I think that's much more reasonable given that SGX doesn't support filesystem stuff at all.~

I've corrected the misleading panic messages in `temp_dir` for UEFI and WASI, aside from that, this PR only consists of code moves.

CC @jethrogb @raoulstrackx @aditijannu for the SGX change (resolved)
This commit is contained in:
Jonathan Brouwer
2026-03-23 12:14:57 +01:00
committed by GitHub
36 changed files with 132 additions and 517 deletions
+10 -10
View File
@@ -15,7 +15,7 @@
use crate::num::NonZero;
use crate::ops::Try;
use crate::path::{Path, PathBuf};
use crate::sys::{env as env_imp, os as os_imp};
use crate::sys::{env as env_imp, paths as paths_imp};
use crate::{array, fmt, io, sys};
/// Returns the current working directory as a [`PathBuf`].
@@ -51,7 +51,7 @@
#[doc(alias = "GetCurrentDirectory")]
#[stable(feature = "env", since = "1.0.0")]
pub fn current_dir() -> io::Result<PathBuf> {
os_imp::getcwd()
paths_imp::getcwd()
}
/// Changes the current working directory to the specified path.
@@ -78,7 +78,7 @@ pub fn current_dir() -> io::Result<PathBuf> {
#[doc(alias = "chdir", alias = "SetCurrentDirectory", alias = "SetCurrentDirectoryW")]
#[stable(feature = "env", since = "1.0.0")]
pub fn set_current_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
os_imp::chdir(path.as_ref())
paths_imp::chdir(path.as_ref())
}
/// An iterator over a snapshot of the environment variables of this process.
@@ -444,7 +444,7 @@ pub unsafe fn remove_var<K: AsRef<OsStr>>(key: K) {
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[stable(feature = "env", since = "1.0.0")]
pub struct SplitPaths<'a> {
inner: os_imp::SplitPaths<'a>,
inner: paths_imp::SplitPaths<'a>,
}
/// Parses input according to platform conventions for the `PATH`
@@ -480,7 +480,7 @@ pub struct SplitPaths<'a> {
/// ```
#[stable(feature = "env", since = "1.0.0")]
pub fn split_paths<T: AsRef<OsStr> + ?Sized>(unparsed: &T) -> SplitPaths<'_> {
SplitPaths { inner: os_imp::split_paths(unparsed.as_ref()) }
SplitPaths { inner: paths_imp::split_paths(unparsed.as_ref()) }
}
#[stable(feature = "env", since = "1.0.0")]
@@ -508,7 +508,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
#[derive(Debug)]
#[stable(feature = "env", since = "1.0.0")]
pub struct JoinPathsError {
inner: os_imp::JoinPathsError,
inner: paths_imp::JoinPathsError,
}
/// Joins a collection of [`Path`]s appropriately for the `PATH`
@@ -579,7 +579,7 @@ pub fn join_paths<I, T>(paths: I) -> Result<OsString, JoinPathsError>
I: IntoIterator<Item = T>,
T: AsRef<OsStr>,
{
os_imp::join_paths(paths.into_iter()).map_err(|e| JoinPathsError { inner: e })
paths_imp::join_paths(paths.into_iter()).map_err(|e| JoinPathsError { inner: e })
}
#[stable(feature = "env", since = "1.0.0")]
@@ -641,7 +641,7 @@ fn description(&self) -> &str {
#[must_use]
#[stable(feature = "env", since = "1.0.0")]
pub fn home_dir() -> Option<PathBuf> {
os_imp::home_dir()
paths_imp::home_dir()
}
/// Returns the path of a temporary directory.
@@ -701,7 +701,7 @@ pub fn home_dir() -> Option<PathBuf> {
#[doc(alias = "GetTempPath", alias = "GetTempPath2")]
#[stable(feature = "env", since = "1.0.0")]
pub fn temp_dir() -> PathBuf {
os_imp::temp_dir()
paths_imp::temp_dir()
}
/// Returns the full filesystem path of the current running executable.
@@ -752,7 +752,7 @@ pub fn temp_dir() -> PathBuf {
/// ```
#[stable(feature = "env", since = "1.0.0")]
pub fn current_exe() -> io::Result<PathBuf> {
os_imp::current_exe()
paths_imp::current_exe()
}
/// An iterator over the arguments of a process, yielding a [`String`] value for
+1 -1
View File
@@ -12,9 +12,9 @@
use crate::os::windows::prelude::*;
use crate::path::{Path, PathBuf};
use crate::sys::helpers::WStrUnits;
use crate::sys::pal::os::current_exe;
use crate::sys::pal::{ensure_no_nuls, fill_utf16_buf};
use crate::sys::path::get_long_path;
use crate::sys::paths::current_exe;
use crate::sys::{AsInner, c, to_u16s};
use crate::{io, iter, ptr};
+3
View File
@@ -1,6 +1,9 @@
use crate::sys::pal::{api, c};
use crate::{io, ptr};
#[cfg(test)]
mod tests;
pub fn errno() -> i32 {
api::get_last_error().code as i32
}
@@ -1,5 +1,5 @@
use crate::io::Error;
use crate::sys::c;
use crate::sys::pal::c;
// tests `error_string` above
#[test]
+1
View File
@@ -18,6 +18,7 @@
pub mod net;
pub mod os_str;
pub mod path;
pub mod paths;
pub mod pipe;
pub mod platform_version;
pub mod process;
-1
View File
@@ -22,7 +22,6 @@
use crate::sys::env;
pub mod futex;
pub mod os;
pub mod time;
pub fn unsupported<T>() -> io::Result<T> {
-57
View File
@@ -1,57 +0,0 @@
use crate::ffi::{OsStr, OsString};
use crate::marker::PhantomData;
use crate::path::{self, PathBuf};
use crate::sys::unsupported;
use crate::{fmt, io};
pub fn getcwd() -> io::Result<PathBuf> {
Ok(PathBuf::from("/"))
}
pub fn chdir(_: &path::Path) -> io::Result<()> {
unsupported()
}
pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);
pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
panic!("unsupported")
}
impl<'a> Iterator for SplitPaths<'a> {
type Item = PathBuf;
fn next(&mut self) -> Option<PathBuf> {
self.0
}
}
#[derive(Debug)]
pub struct JoinPathsError;
pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
where
I: Iterator<Item = T>,
T: AsRef<OsStr>,
{
Err(JoinPathsError)
}
impl fmt::Display for JoinPathsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"not supported on hermit yet".fmt(f)
}
}
impl crate::error::Error for JoinPathsError {}
pub fn current_exe() -> io::Result<PathBuf> {
unsupported()
}
pub fn temp_dir() -> PathBuf {
PathBuf::from("/tmp")
}
pub fn home_dir() -> Option<PathBuf> {
None
}
-2
View File
@@ -1,7 +1,5 @@
#![allow(unsafe_op_in_unsafe_fn)]
pub mod os;
pub use moto_rt::futex;
use crate::io;
-64
View File
@@ -1,64 +0,0 @@
use super::map_motor_error;
use crate::error::Error as StdError;
use crate::ffi::{OsStr, OsString};
use crate::marker::PhantomData;
use crate::os::motor::ffi::OsStrExt;
use crate::path::{self, PathBuf};
use crate::{fmt, io};
pub fn getcwd() -> io::Result<PathBuf> {
moto_rt::fs::getcwd().map(PathBuf::from).map_err(map_motor_error)
}
pub fn chdir(path: &path::Path) -> io::Result<()> {
moto_rt::fs::chdir(path.as_os_str().as_str()).map_err(map_motor_error)
}
pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);
pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
panic!("unsupported")
}
impl<'a> Iterator for SplitPaths<'a> {
type Item = PathBuf;
fn next(&mut self) -> Option<PathBuf> {
self.0
}
}
#[derive(Debug)]
pub struct JoinPathsError;
pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
where
I: Iterator<Item = T>,
T: AsRef<OsStr>,
{
Err(JoinPathsError)
}
impl fmt::Display for JoinPathsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"not supported on this platform yet".fmt(f)
}
}
impl StdError for JoinPathsError {
#[allow(deprecated)]
fn description(&self) -> &str {
"not supported on this platform yet"
}
}
pub fn current_exe() -> io::Result<PathBuf> {
moto_rt::process::current_exe().map(PathBuf::from).map_err(map_motor_error)
}
pub fn temp_dir() -> PathBuf {
PathBuf::from(moto_rt::fs::TEMP_DIR)
}
pub fn home_dir() -> Option<PathBuf> {
None
}
-1
View File
@@ -10,7 +10,6 @@
pub mod abi;
mod libunwind_integration;
pub mod os;
pub mod thread_parking;
pub mod waitqueue;
-57
View File
@@ -1,57 +0,0 @@
use crate::ffi::{OsStr, OsString};
use crate::marker::PhantomData;
use crate::path::{self, PathBuf};
use crate::sys::{sgx_ineffective, unsupported};
use crate::{fmt, io};
pub fn getcwd() -> io::Result<PathBuf> {
unsupported()
}
pub fn chdir(_: &path::Path) -> io::Result<()> {
sgx_ineffective(())
}
pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);
pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
panic!("unsupported")
}
impl<'a> Iterator for SplitPaths<'a> {
type Item = PathBuf;
fn next(&mut self) -> Option<PathBuf> {
self.0
}
}
#[derive(Debug)]
pub struct JoinPathsError;
pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
where
I: Iterator<Item = T>,
T: AsRef<OsStr>,
{
Err(JoinPathsError)
}
impl fmt::Display for JoinPathsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"not supported in SGX yet".fmt(f)
}
}
impl crate::error::Error for JoinPathsError {}
pub fn current_exe() -> io::Result<PathBuf> {
unsupported()
}
pub fn temp_dir() -> PathBuf {
panic!("no filesystem in SGX")
}
pub fn home_dir() -> Option<PathBuf> {
None
}
-1
View File
@@ -19,7 +19,6 @@ pub mod itron {
// `error` is `pub(crate)` so that it can be accessed by `itron/error.rs` as
// `crate::sys::error`
pub(crate) mod error;
pub mod os;
pub use self::itron::thread_parking;
// SAFETY: must be called only once during runtime initialization.
-56
View File
@@ -1,56 +0,0 @@
use super::unsupported;
use crate::ffi::{OsStr, OsString};
use crate::path::{self, PathBuf};
use crate::{fmt, io};
pub fn getcwd() -> io::Result<PathBuf> {
unsupported()
}
pub fn chdir(_: &path::Path) -> io::Result<()> {
unsupported()
}
pub struct SplitPaths<'a>(&'a !);
pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
panic!("unsupported")
}
impl<'a> Iterator for SplitPaths<'a> {
type Item = PathBuf;
fn next(&mut self) -> Option<PathBuf> {
*self.0
}
}
#[derive(Debug)]
pub struct JoinPathsError;
pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
where
I: Iterator<Item = T>,
T: AsRef<OsStr>,
{
Err(JoinPathsError)
}
impl fmt::Display for JoinPathsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"not supported on this platform yet".fmt(f)
}
}
impl crate::error::Error for JoinPathsError {}
pub fn current_exe() -> io::Result<PathBuf> {
unsupported()
}
pub fn temp_dir() -> PathBuf {
panic!("no standard temporary directory on this platform")
}
pub fn home_dir() -> Option<PathBuf> {
None
}
-1
View File
@@ -7,7 +7,6 @@
#![allow(dead_code)]
pub mod conf;
pub mod os;
#[path = "../unix/time.rs"]
pub mod time;
-62
View File
@@ -1,62 +0,0 @@
//! Implementation of `std::os` functionality for teeos
use core::marker::PhantomData;
use super::unsupported;
use crate::ffi::{OsStr, OsString};
use crate::path::PathBuf;
use crate::{fmt, io, path};
// Everything below are stubs and copied from unsupported.rs
pub fn getcwd() -> io::Result<PathBuf> {
unsupported()
}
pub fn chdir(_: &path::Path) -> io::Result<()> {
unsupported()
}
pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);
pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
panic!("unsupported")
}
impl<'a> Iterator for SplitPaths<'a> {
type Item = PathBuf;
fn next(&mut self) -> Option<PathBuf> {
self.0
}
}
#[derive(Debug)]
pub struct JoinPathsError;
pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
where
I: Iterator<Item = T>,
T: AsRef<OsStr>,
{
Err(JoinPathsError)
}
impl fmt::Display for JoinPathsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"not supported on this platform yet".fmt(f)
}
}
impl crate::error::Error for JoinPathsError {}
pub fn current_exe() -> io::Result<PathBuf> {
unsupported()
}
pub fn temp_dir() -> PathBuf {
panic!("no filesystem on this platform")
}
pub fn home_dir() -> Option<PathBuf> {
None
}
-2
View File
@@ -3,7 +3,5 @@
#[path = "../unsupported/common.rs"]
#[deny(unsafe_op_in_unsafe_fn)]
mod common;
#[path = "../unsupported/os.rs"]
pub mod os;
pub use common::*;
-1
View File
@@ -14,7 +14,6 @@
#![forbid(unsafe_op_in_unsafe_fn)]
pub mod helpers;
pub mod os;
pub mod system_time;
#[cfg(test)]
-1
View File
@@ -8,7 +8,6 @@
pub mod futex;
#[cfg(target_os = "linux")]
pub mod linux;
pub mod os;
pub mod stack_overflow;
pub mod sync;
pub mod thread_parking;
@@ -1,6 +1,4 @@
#![deny(unsafe_op_in_unsafe_fn)]
pub mod os;
mod common;
pub use common::*;
-57
View File
@@ -1,57 +0,0 @@
use super::unsupported;
use crate::ffi::{OsStr, OsString};
use crate::marker::PhantomData;
use crate::path::{self, PathBuf};
use crate::{fmt, io};
pub fn getcwd() -> io::Result<PathBuf> {
unsupported()
}
pub fn chdir(_: &path::Path) -> io::Result<()> {
unsupported()
}
pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);
pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
panic!("unsupported")
}
impl<'a> Iterator for SplitPaths<'a> {
type Item = PathBuf;
fn next(&mut self) -> Option<PathBuf> {
self.0
}
}
#[derive(Debug)]
pub struct JoinPathsError;
pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
where
I: Iterator<Item = T>,
T: AsRef<OsStr>,
{
Err(JoinPathsError)
}
impl fmt::Display for JoinPathsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"not supported on this platform yet".fmt(f)
}
}
impl crate::error::Error for JoinPathsError {}
pub fn current_exe() -> io::Result<PathBuf> {
unsupported()
}
pub fn temp_dir() -> PathBuf {
panic!("no filesystem on this platform")
}
pub fn home_dir() -> Option<PathBuf> {
None
}
-3
View File
@@ -1,6 +1,3 @@
#[path = "../unsupported/os.rs"]
pub mod os;
#[expect(dead_code)]
#[path = "../unsupported/common.rs"]
mod unsupported_common;
-1
View File
@@ -10,7 +10,6 @@
#[allow(unused)]
#[path = "../wasm/atomics/futex.rs"]
pub mod futex;
pub mod os;
pub mod stack_overflow;
#[path = "../unix/time.rs"]
pub mod time;
-3
View File
@@ -16,9 +16,6 @@
#![deny(unsafe_op_in_unsafe_fn)]
#[path = "../unsupported/os.rs"]
pub mod os;
#[cfg(target_feature = "atomics")]
#[path = "atomics/futex.rs"]
pub mod futex;
-1
View File
@@ -18,7 +18,6 @@
#[cfg(not(target_vendor = "win7"))]
pub mod futex;
pub mod handle;
pub mod os;
pub mod time;
cfg_select! {
// We don't care about printing nice error messages for panic=immediate-abort
-1
View File
@@ -1,6 +1,5 @@
#![forbid(unsafe_op_in_unsafe_fn)]
pub mod os;
pub mod params;
#[path = "../unsupported/common.rs"]
-57
View File
@@ -1,57 +0,0 @@
use super::unsupported;
use crate::ffi::{OsStr, OsString};
use crate::marker::PhantomData;
use crate::path::{self, PathBuf};
use crate::{fmt, io};
pub fn getcwd() -> io::Result<PathBuf> {
unsupported()
}
pub fn chdir(_: &path::Path) -> io::Result<()> {
unsupported()
}
pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);
pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
panic!("unsupported")
}
impl<'a> Iterator for SplitPaths<'a> {
type Item = PathBuf;
fn next(&mut self) -> Option<PathBuf> {
self.0
}
}
#[derive(Debug)]
pub struct JoinPathsError;
pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
where
I: Iterator<Item = T>,
T: AsRef<OsStr>,
{
Err(JoinPathsError)
}
impl fmt::Display for JoinPathsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"not supported on this platform yet".fmt(f)
}
}
impl crate::error::Error for JoinPathsError {}
pub fn current_exe() -> io::Result<PathBuf> {
unsupported()
}
pub fn temp_dir() -> PathBuf {
panic!("no filesystem on this platform")
}
pub fn home_dir() -> Option<PathBuf> {
None
}
-1
View File
@@ -11,7 +11,6 @@
pub const WORD_SIZE: usize = size_of::<u32>();
pub mod abi;
pub mod os;
use crate::io as std_io;
+10
View File
@@ -0,0 +1,10 @@
use crate::io;
use crate::path::PathBuf;
pub fn getcwd() -> io::Result<PathBuf> {
Ok(PathBuf::from("/"))
}
pub fn temp_dir() -> PathBuf {
PathBuf::from("/tmp")
}
+59
View File
@@ -0,0 +1,59 @@
cfg_select! {
target_os = "hermit" => {
mod hermit;
#[expect(dead_code)]
mod unsupported;
mod imp {
pub use super::hermit::{getcwd, temp_dir};
pub use super::unsupported::{chdir, SplitPaths, split_paths, JoinPathsError, join_paths, current_exe, home_dir};
}
}
target_os = "motor" => {
mod motor;
#[expect(dead_code)]
mod unsupported;
mod imp {
pub use super::motor::{getcwd, chdir, current_exe, temp_dir};
pub use super::unsupported::{SplitPaths, split_paths, JoinPathsError, join_paths, home_dir};
}
}
all(target_vendor = "fortanix", target_env = "sgx") => {
mod sgx;
#[expect(dead_code)]
mod unsupported;
mod imp {
pub use super::sgx::chdir;
pub use super::unsupported::{getcwd, SplitPaths, split_paths, JoinPathsError, join_paths, current_exe, temp_dir, home_dir};
}
}
target_os = "uefi" => {
mod uefi;
use uefi as imp;
}
target_family = "unix" => {
mod unix;
use unix as imp;
}
target_os = "wasi" => {
mod wasi;
#[expect(dead_code)]
mod unsupported;
mod imp {
pub use super::wasi::{getcwd, chdir, temp_dir};
pub use super::unsupported::{current_exe, SplitPaths, split_paths, JoinPathsError, join_paths, home_dir};
}
}
target_os = "windows" => {
mod windows;
use windows as imp;
}
_ => {
mod unsupported;
use unsupported as imp;
}
}
pub use imp::{
JoinPathsError, SplitPaths, chdir, current_exe, getcwd, home_dir, join_paths, split_paths,
temp_dir,
};
+20
View File
@@ -0,0 +1,20 @@
use crate::io;
use crate::os::motor::ffi::OsStrExt;
use crate::path::{self, PathBuf};
use crate::sys::pal::map_motor_error;
pub fn getcwd() -> io::Result<PathBuf> {
moto_rt::fs::getcwd().map(PathBuf::from).map_err(map_motor_error)
}
pub fn chdir(path: &path::Path) -> io::Result<()> {
moto_rt::fs::chdir(path.as_os_str().as_str()).map_err(map_motor_error)
}
pub fn current_exe() -> io::Result<PathBuf> {
moto_rt::process::current_exe().map(PathBuf::from).map_err(map_motor_error)
}
pub fn temp_dir() -> PathBuf {
PathBuf::from(moto_rt::fs::TEMP_DIR)
}
+7
View File
@@ -0,0 +1,7 @@
use crate::io;
use crate::path::Path;
use crate::sys::pal::sgx_ineffective;
pub fn chdir(_: &Path) -> io::Result<()> {
sgx_ineffective(())
}
@@ -1,9 +1,9 @@
use r_efi::efi::protocols::{device_path, loaded_image_device_path};
use super::{helpers, unsupported_err};
use crate::ffi::{OsStr, OsString};
use crate::os::uefi::ffi::{OsStrExt, OsStringExt};
use crate::path::{self, PathBuf};
use crate::sys::pal::{helpers, unsupported_err};
use crate::{fmt, io};
const PATHS_SEP: u16 = b';' as u16;
@@ -115,7 +115,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
}
pub fn temp_dir() -> PathBuf {
panic!("no filesystem on this platform")
panic!("UEFI doesn't have a dedicated temp directory")
}
pub fn home_dir() -> Option<PathBuf> {
@@ -7,8 +7,8 @@
use crate::ffi::{CStr, OsStr, OsString};
use crate::os::unix::prelude::*;
use crate::path::{self, PathBuf};
use crate::sys::cvt;
use crate::sys::helpers::run_path_with_cstr;
use crate::sys::pal::cvt;
use crate::{fmt, io, iter, mem, ptr, slice, str};
const PATH_SEPARATOR: u8 = b':';
@@ -47,7 +47,7 @@ pub fn getcwd() -> io::Result<PathBuf> {
#[cfg(target_os = "espidf")]
pub fn chdir(_p: &path::Path) -> io::Result<()> {
super::unsupported::unsupported()
crate::sys::pal::unsupported::unsupported()
}
#[cfg(not(target_os = "espidf"))]
@@ -372,7 +372,7 @@ pub fn current_exe() -> io::Result<PathBuf> {
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita"))]
pub fn current_exe() -> io::Result<PathBuf> {
super::unsupported::unsupported()
crate::sys::pal::unsupported::unsupported()
}
#[cfg(target_os = "fuchsia")]
@@ -1,7 +1,7 @@
use super::unsupported;
use crate::ffi::{OsStr, OsString};
use crate::marker::PhantomData;
use crate::path::{self, PathBuf};
use crate::sys::pal::unsupported;
use crate::{fmt, io};
pub fn getcwd() -> io::Result<PathBuf> {
@@ -1,12 +1,10 @@
#![forbid(unsafe_op_in_unsafe_fn)]
use crate::ffi::{CStr, OsStr, OsString};
use crate::marker::PhantomData;
use crate::ffi::{CStr, OsString};
use crate::io;
use crate::os::wasi::prelude::*;
use crate::path::{self, PathBuf};
use crate::sys::helpers::run_path_with_cstr;
use crate::sys::unsupported;
use crate::{fmt, io};
pub fn getcwd() -> io::Result<PathBuf> {
let mut buf = Vec::with_capacity(512);
@@ -42,46 +40,6 @@ pub fn chdir(p: &path::Path) -> io::Result<()> {
}
}
pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);
pub fn split_paths(_unparsed: &OsStr) -> SplitPaths<'_> {
panic!("unsupported")
}
impl<'a> Iterator for SplitPaths<'a> {
type Item = PathBuf;
fn next(&mut self) -> Option<PathBuf> {
self.0
}
}
#[derive(Debug)]
pub struct JoinPathsError;
pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError>
where
I: Iterator<Item = T>,
T: AsRef<OsStr>,
{
Err(JoinPathsError)
}
impl fmt::Display for JoinPathsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"not supported on wasm yet".fmt(f)
}
}
impl crate::error::Error for JoinPathsError {}
pub fn current_exe() -> io::Result<PathBuf> {
unsupported()
}
pub fn temp_dir() -> PathBuf {
panic!("no filesystem on wasm")
}
pub fn home_dir() -> Option<PathBuf> {
None
panic!("not supported by WASI yet")
}
@@ -2,17 +2,13 @@
#![allow(nonstandard_style)]
#[cfg(test)]
mod tests;
use super::api;
#[cfg(not(target_vendor = "uwp"))]
use super::api::WinError;
use crate::ffi::{OsStr, OsString};
use crate::os::windows::ffi::EncodeWide;
use crate::os::windows::prelude::*;
use crate::path::{self, PathBuf};
use crate::sys::pal::{c, cvt};
#[cfg(not(target_vendor = "uwp"))]
use crate::sys::pal::api::WinError;
use crate::sys::pal::{api, c, cvt, fill_utf16_buf, os2path};
use crate::{fmt, io, ptr};
pub struct SplitPaths<'a> {
@@ -56,11 +52,7 @@ fn next(&mut self) -> Option<PathBuf> {
}
}
if !must_yield && in_progress.is_empty() {
None
} else {
Some(super::os2path(&in_progress))
}
if !must_yield && in_progress.is_empty() { None } else { Some(os2path(&in_progress)) }
}
}
@@ -104,14 +96,11 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
impl crate::error::Error for JoinPathsError {}
pub fn current_exe() -> io::Result<PathBuf> {
super::fill_utf16_buf(
|buf, sz| unsafe { c::GetModuleFileNameW(ptr::null_mut(), buf, sz) },
super::os2path,
)
fill_utf16_buf(|buf, sz| unsafe { c::GetModuleFileNameW(ptr::null_mut(), buf, sz) }, os2path)
}
pub fn getcwd() -> io::Result<PathBuf> {
super::fill_utf16_buf(|buf, sz| unsafe { c::GetCurrentDirectoryW(sz, buf) }, super::os2path)
fill_utf16_buf(|buf, sz| unsafe { c::GetCurrentDirectoryW(sz, buf) }, os2path)
}
pub fn chdir(p: &path::Path) -> io::Result<()> {
@@ -123,7 +112,7 @@ pub fn chdir(p: &path::Path) -> io::Result<()> {
}
pub fn temp_dir() -> PathBuf {
super::fill_utf16_buf(|buf, sz| unsafe { c::GetTempPath2W(sz, buf) }, super::os2path).unwrap()
fill_utf16_buf(|buf, sz| unsafe { c::GetTempPath2W(sz, buf) }, os2path).unwrap()
}
#[cfg(all(not(target_vendor = "uwp"), not(target_vendor = "win7")))]
@@ -132,7 +121,7 @@ fn home_dir_crt() -> Option<PathBuf> {
// Defined in processthreadsapi.h.
const CURRENT_PROCESS_TOKEN: usize = -4_isize as usize;
super::fill_utf16_buf(
fill_utf16_buf(
|buf, mut sz| {
// GetUserProfileDirectoryW does not quite use the usual protocol for
// negotiating the buffer size, so we have to translate.
@@ -146,7 +135,7 @@ fn home_dir_crt() -> Option<PathBuf> {
_ => sz - 1, // sz includes the null terminator
}
},
super::os2path,
os2path,
)
.ok()
}
@@ -163,7 +152,7 @@ fn home_dir_crt() -> Option<PathBuf> {
return None;
}
let _handle = Handle::from_raw_handle(token);
super::fill_utf16_buf(
fill_utf16_buf(
|buf, mut sz| {
match c::GetUserProfileDirectoryW(token, buf, &mut sz) {
0 if api::get_last_error() != WinError::INSUFFICIENT_BUFFER => 0,
@@ -171,7 +160,7 @@ fn home_dir_crt() -> Option<PathBuf> {
_ => sz - 1, // sz includes the null terminator
}
},
super::os2path,
os2path,
)
.ok()
}