Skip to content

Commit 89f85cb

Browse files
committedMar 22, 2025··
std: move process implementations to sys
As per #117276, this moves the implementations of `Process` and friends out of the `pal` module and into the `sys` module, removing quite a lot of error-prone `#[path]` imports in the process (hah, get it ;-)). I've also made the `zircon` module a dedicated submodule of `pal::unix`, hopefully we can move some other definitions there as well (they are currently quite a lot of duplications in `sys`). Also, the `ensure_no_nuls` function on Windows now lives in `sys::pal::windows` – it's not specific to processes and shared by the argument implementation.
1 parent db68788 commit 89f85cb

File tree

32 files changed

+90
-104
lines changed

32 files changed

+90
-104
lines changed
 

‎library/std/src/sys/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub mod io;
1717
pub mod net;
1818
pub mod os_str;
1919
pub mod path;
20+
pub mod process;
2021
pub mod random;
2122
pub mod stdio;
2223
pub mod sync;

‎library/std/src/sys/pal/hermit/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ pub mod futex;
2525
pub mod os;
2626
#[path = "../unsupported/pipe.rs"]
2727
pub mod pipe;
28-
#[path = "../unsupported/process.rs"]
29-
pub mod process;
3028
pub mod thread;
3129
pub mod time;
3230

‎library/std/src/sys/pal/sgx/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ mod libunwind_integration;
1616
pub mod os;
1717
#[path = "../unsupported/pipe.rs"]
1818
pub mod pipe;
19-
#[path = "../unsupported/process.rs"]
20-
pub mod process;
2119
pub mod thread;
2220
pub mod thread_parking;
2321
pub mod time;

‎library/std/src/sys/pal/solid/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ pub(crate) mod error;
2525
pub mod os;
2626
#[path = "../unsupported/pipe.rs"]
2727
pub mod pipe;
28-
#[path = "../unsupported/process.rs"]
29-
pub mod process;
3028
pub use self::itron::{thread, thread_parking};
3129
pub mod time;
3230

‎library/std/src/sys/pal/teeos/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ pub mod env;
1414
pub mod os;
1515
#[path = "../unsupported/pipe.rs"]
1616
pub mod pipe;
17-
#[path = "../unsupported/process.rs"]
18-
pub mod process;
1917
pub mod thread;
2018
#[allow(non_upper_case_globals)]
2119
#[path = "../unix/time.rs"]

‎library/std/src/sys/pal/uefi/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub mod helpers;
1919
pub mod os;
2020
#[path = "../unsupported/pipe.rs"]
2121
pub mod pipe;
22-
pub mod process;
2322
pub mod thread;
2423
pub mod time;
2524

‎library/std/src/sys/pal/unix/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ pub mod weak;
99
pub mod args;
1010
pub mod env;
1111
pub mod fd;
12+
#[cfg(target_os = "fuchsia")]
13+
pub mod fuchsia;
1214
pub mod futex;
1315
#[cfg(any(target_os = "linux", target_os = "android"))]
1416
pub mod kernel_copy;
1517
#[cfg(target_os = "linux")]
1618
pub mod linux;
1719
pub mod os;
1820
pub mod pipe;
19-
pub mod process;
2021
pub mod stack_overflow;
2122
pub mod sync;
2223
pub mod thread;
@@ -419,7 +420,7 @@ cfg_if::cfg_if! {
419420
}
420421

421422
#[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita", target_os = "nuttx"))]
422-
mod unsupported {
423+
pub mod unsupported {
423424
use crate::io;
424425

425426
pub fn unsupported<T>() -> io::Result<T> {

‎library/std/src/sys/pal/unix/process/mod.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎library/std/src/sys/pal/unsupported/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pub mod args;
44
pub mod env;
55
pub mod os;
66
pub mod pipe;
7-
pub mod process;
87
pub mod thread;
98
pub mod time;
109

‎library/std/src/sys/pal/wasi/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ pub mod futex;
2323
pub mod os;
2424
#[path = "../unsupported/pipe.rs"]
2525
pub mod pipe;
26-
#[path = "../unsupported/process.rs"]
27-
pub mod process;
2826
pub mod thread;
2927
pub mod time;
3028

‎library/std/src/sys/pal/wasip2/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ pub mod futex;
2020
pub mod os;
2121
#[path = "../unsupported/pipe.rs"]
2222
pub mod pipe;
23-
#[path = "../unsupported/process.rs"]
24-
pub mod process;
2523
#[path = "../wasi/thread.rs"]
2624
pub mod thread;
2725
#[path = "../wasi/time.rs"]

‎library/std/src/sys/pal/wasm/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ pub mod env;
2323
pub mod os;
2424
#[path = "../unsupported/pipe.rs"]
2525
pub mod pipe;
26-
#[path = "../unsupported/process.rs"]
27-
pub mod process;
2826
#[path = "../unsupported/time.rs"]
2927
pub mod time;
3028

‎library/std/src/sys/pal/windows/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
#[cfg(test)]
77
mod tests;
88

9+
use super::ensure_no_nuls;
910
use super::os::current_exe;
1011
use crate::ffi::{OsStr, OsString};
1112
use crate::num::NonZero;
1213
use crate::os::windows::prelude::*;
1314
use crate::path::{Path, PathBuf};
1415
use crate::sys::path::get_long_path;
15-
use crate::sys::process::ensure_no_nuls;
1616
use crate::sys::{c, to_u16s};
1717
use crate::sys_common::AsInner;
1818
use crate::sys_common::wstr::WStrUnits;

‎library/std/src/sys/pal/windows/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub mod futex;
2222
pub mod handle;
2323
pub mod os;
2424
pub mod pipe;
25-
pub mod process;
2625
pub mod thread;
2726
pub mod time;
2827
cfg_if::cfg_if! {
@@ -287,6 +286,14 @@ pub fn truncate_utf16_at_nul(v: &[u16]) -> &[u16] {
287286
}
288287
}
289288

289+
pub fn ensure_no_nuls<T: AsRef<OsStr>>(s: T) -> crate::io::Result<T> {
290+
if s.as_ref().encode_wide().any(|b| b == 0) {
291+
Err(crate::io::const_error!(ErrorKind::InvalidInput, "nul byte found in provided data"))
292+
} else {
293+
Ok(s)
294+
}
295+
}
296+
290297
pub trait IsZero {
291298
fn is_zero(&self) -> bool;
292299
}

‎library/std/src/sys/pal/xous/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ pub mod env;
66
pub mod os;
77
#[path = "../unsupported/pipe.rs"]
88
pub mod pipe;
9-
#[path = "../unsupported/process.rs"]
10-
pub mod process;
119
pub mod thread;
1210
pub mod time;
1311

‎library/std/src/sys/pal/zkvm/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ pub mod env;
1717
pub mod os;
1818
#[path = "../unsupported/pipe.rs"]
1919
pub mod pipe;
20-
#[path = "../unsupported/process.rs"]
21-
pub mod process;
2220
#[path = "../unsupported/thread.rs"]
2321
pub mod thread;
2422
#[path = "../unsupported/time.rs"]

‎library/std/src/sys/process/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cfg_if::cfg_if! {
2+
if #[cfg(target_family = "unix")] {
3+
mod unix;
4+
use unix as imp;
5+
} else if #[cfg(target_os = "windows")] {
6+
mod windows;
7+
use windows as imp;
8+
} else if #[cfg(target_os = "uefi")] {
9+
mod uefi;
10+
use uefi as imp;
11+
} else {
12+
mod unsupported;
13+
use unsupported as imp;
14+
}
15+
}
16+
17+
pub use imp::{
18+
Command, CommandArgs, EnvKey, ExitCode, ExitStatus, ExitStatusError, Process, Stdio, StdioPipes,
19+
};

‎library/std/src/sys/pal/uefi/process.rs renamed to ‎library/std/src/sys/process/uefi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use r_efi::protocols::simple_text_output;
22

3-
use super::helpers;
43
use crate::collections::BTreeMap;
54
pub use crate::ffi::OsString as EnvKey;
65
use crate::ffi::{OsStr, OsString};
76
use crate::num::{NonZero, NonZeroI32};
87
use crate::path::Path;
98
use crate::sys::fs::File;
9+
use crate::sys::pal::helpers;
10+
use crate::sys::pal::os::error_string;
1011
use crate::sys::pipe::AnonPipe;
1112
use crate::sys::unsupported;
1213
use crate::sys_common::process::{CommandEnv, CommandEnvs};
@@ -225,7 +226,7 @@ impl ExitStatus {
225226

226227
impl fmt::Display for ExitStatus {
227228
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
228-
let err_str = super::os::error_string(self.0.as_usize());
229+
let err_str = error_string(self.0.as_usize());
229230
write!(f, "{}", err_str)
230231
}
231232
}
@@ -241,7 +242,7 @@ pub struct ExitStatusError(r_efi::efi::Status);
241242

242243
impl fmt::Debug for ExitStatusError {
243244
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
244-
let err_str = super::os::error_string(self.0.as_usize());
245+
let err_str = error_string(self.0.as_usize());
245246
write!(f, "{}", err_str)
246247
}
247248
}
@@ -335,15 +336,14 @@ impl<'a> fmt::Debug for CommandArgs<'a> {
335336
mod uefi_command_internal {
336337
use r_efi::protocols::{loaded_image, simple_text_output};
337338

338-
use super::super::helpers;
339339
use crate::ffi::{OsStr, OsString};
340340
use crate::io::{self, const_error};
341341
use crate::mem::MaybeUninit;
342342
use crate::os::uefi::env::{boot_services, image_handle, system_table};
343343
use crate::os::uefi::ffi::{OsStrExt, OsStringExt};
344344
use crate::ptr::NonNull;
345345
use crate::slice;
346-
use crate::sys::pal::uefi::helpers::OwnedTable;
346+
use crate::sys::pal::helpers::{self, OwnedTable};
347347
use crate::sys_common::wstr::WStrUnits;
348348

349349
pub struct Image {

‎library/std/src/sys/pal/unix/process/process_common.rs renamed to ‎library/std/src/sys/process/unix/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ cfg_if::cfg_if! {
5454

5555
let bit = (signum - 1) as usize;
5656
if set.is_null() || bit >= (8 * size_of::<sigset_t>()) {
57-
crate::sys::pal::unix::os::set_errno(libc::EINVAL);
57+
crate::sys::pal::os::set_errno(libc::EINVAL);
5858
return -1;
5959
}
6060
let raw = slice::from_raw_parts_mut(

‎library/std/src/sys/pal/unix/process/process_fuchsia.rs renamed to ‎library/std/src/sys/process/unix/fuchsia.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use libc::{c_int, size_t};
22

3+
use super::common::*;
34
use crate::num::NonZero;
4-
use crate::sys::process::process_common::*;
5-
use crate::sys::process::zircon::{Handle, zx_handle_t};
5+
use crate::sys::pal::fuchsia::*;
66
use crate::{fmt, io, mem, ptr};
77

88
////////////////////////////////////////////////////////////////////////////////
@@ -58,8 +58,6 @@ impl Command {
5858
stdio: ChildPipes,
5959
maybe_envp: Option<&CStringArray>,
6060
) -> io::Result<zx_handle_t> {
61-
use crate::sys::process::zircon::*;
62-
6361
let envp = match maybe_envp {
6462
// None means to clone the current environment, which is done in the
6563
// flags below.
@@ -152,8 +150,6 @@ impl Process {
152150
}
153151

154152
pub fn kill(&mut self) -> io::Result<()> {
155-
use crate::sys::process::zircon::*;
156-
157153
unsafe {
158154
zx_cvt(zx_task_kill(self.handle.raw()))?;
159155
}
@@ -162,8 +158,6 @@ impl Process {
162158
}
163159

164160
pub fn wait(&mut self) -> io::Result<ExitStatus> {
165-
use crate::sys::process::zircon::*;
166-
167161
let mut proc_info: zx_info_process_t = Default::default();
168162
let mut actual: size_t = 0;
169163
let mut avail: size_t = 0;
@@ -194,8 +188,6 @@ impl Process {
194188
}
195189

196190
pub fn try_wait(&mut self) -> io::Result<Option<ExitStatus>> {
197-
use crate::sys::process::zircon::*;
198-
199191
let mut proc_info: zx_info_process_t = Default::default();
200192
let mut actual: size_t = 0;
201193
let mut avail: size_t = 0;
@@ -251,7 +243,7 @@ impl ExitStatus {
251243
None
252244
}
253245

254-
// FIXME: The actually-Unix implementation in process_unix.rs uses WSTOPSIG, WCOREDUMP et al.
246+
// FIXME: The actually-Unix implementation in unix.rs uses WSTOPSIG, WCOREDUMP et al.
255247
// I infer from the implementation of `success`, `code` and `signal` above that these are not
256248
// available on Fuchsia.
257249
//
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#[cfg_attr(any(target_os = "espidf", target_os = "horizon", target_os = "nuttx"), allow(unused))]
2+
mod common;
3+
4+
cfg_if::cfg_if! {
5+
if #[cfg(target_os = "fuchsia")] {
6+
mod fuchsia;
7+
use fuchsia as imp;
8+
} else if #[cfg(target_os = "vxworks")] {
9+
mod vxworks;
10+
use vxworks as imp;
11+
} else if #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "vita", target_os = "nuttx"))] {
12+
mod unsupported;
13+
use unsupported as imp;
14+
} else {
15+
mod unix;
16+
use unix as imp;
17+
}
18+
}
19+
20+
pub use imp::{ExitStatus, ExitStatusError, Process};
21+
22+
pub use self::common::{Command, CommandArgs, ExitCode, Stdio, StdioPipes};
23+
pub use crate::ffi::OsString as EnvKey;

‎library/std/src/sys/pal/unix/process/process_unix.rs renamed to ‎library/std/src/sys/process/unix/unix.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use libc::{c_int, pid_t};
1010
)))]
1111
use libc::{gid_t, uid_t};
1212

13+
use super::common::*;
1314
use crate::io::{self, Error, ErrorKind};
1415
use crate::num::NonZero;
1516
use crate::sys::cvt;
1617
#[cfg(target_os = "linux")]
17-
use crate::sys::pal::unix::linux::pidfd::PidFd;
18-
use crate::sys::process::process_common::*;
18+
use crate::sys::pal::linux::pidfd::PidFd;
1919
use crate::{fmt, mem, sys};
2020

2121
cfg_if::cfg_if! {
@@ -1051,7 +1051,7 @@ impl ExitStatus {
10511051
// true on all actual versions of Unix, is widely assumed, and is specified in SuS
10521052
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
10531053
// true for a platform pretending to be Unix, the tests (our doctests, and also
1054-
// process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
1054+
// unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
10551055
match NonZero::try_from(self.0) {
10561056
/* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)),
10571057
/* was zero, couldn't convert */ Err(_) => Ok(()),
@@ -1232,10 +1232,9 @@ impl ExitStatusError {
12321232

12331233
#[cfg(target_os = "linux")]
12341234
mod linux_child_ext {
1235-
1235+
use crate::io::ErrorKind;
12361236
use crate::os::linux::process as os;
1237-
use crate::sys::pal::unix::ErrorKind;
1238-
use crate::sys::pal::unix::linux::pidfd as imp;
1237+
use crate::sys::pal::linux::pidfd as imp;
12391238
use crate::sys_common::FromInner;
12401239
use crate::{io, mem};
12411240

@@ -1261,10 +1260,9 @@ mod linux_child_ext {
12611260
}
12621261

12631262
#[cfg(test)]
1264-
#[path = "process_unix/tests.rs"]
12651263
mod tests;
12661264

1267-
// See [`process_unsupported_wait_status::compare_with_linux`];
1265+
// See [`unsupported_wait_status::compare_with_linux`];
12681266
#[cfg(all(test, target_os = "linux"))]
1269-
#[path = "process_unsupported/wait_status.rs"]
1270-
mod process_unsupported_wait_status;
1267+
#[path = "unsupported/wait_status.rs"]
1268+
mod unsupported_wait_status;

‎library/std/src/sys/pal/unix/process/process_unsupported.rs renamed to ‎library/std/src/sys/process/unix/unsupported.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use libc::{c_int, pid_t};
22

3+
use super::common::*;
34
use crate::io;
45
use crate::num::NonZero;
5-
use crate::sys::pal::unix::unsupported::*;
6-
use crate::sys::process::process_common::*;
6+
use crate::sys::pal::unsupported::*;
77

88
////////////////////////////////////////////////////////////////////////////////
99
// Command

‎library/std/src/sys/pal/unix/process/process_unsupported/wait_status.rs renamed to ‎library/std/src/sys/process/unix/unsupported/wait_status.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::ffi::c_int;
77
use crate::fmt;
88
use crate::num::NonZero;
99

10-
/// Emulated wait status for use by `process_unsupported.rs`
10+
/// Emulated wait status for use by `unsupported.rs`
1111
///
1212
/// Uses the "traditional unix" encoding. For use on platfors which are `#[cfg(unix)]`
1313
/// but do not actually support subprocesses at all.
@@ -48,7 +48,7 @@ impl ExitStatus {
4848
// true on all actual versions of Unix, is widely assumed, and is specified in SuS
4949
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
5050
// true for a platform pretending to be Unix, the tests (our doctests, and also
51-
// process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
51+
// unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
5252
match NonZero::try_from(self.wait_status) {
5353
/* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)),
5454
/* was zero, couldn't convert */ Err(_) => Ok(()),
@@ -79,5 +79,6 @@ impl ExitStatus {
7979
}
8080

8181
#[cfg(test)]
82-
#[path = "wait_status/tests.rs"] // needed because of strange layout of process_unsupported
82+
#[path = "wait_status/tests.rs"]
83+
// needed because this module is also imported through #[path] for testing purposes
8384
mod tests;

‎library/std/src/sys/pal/unix/process/process_unsupported/wait_status/tests.rs renamed to ‎library/std/src/sys/process/unix/unsupported/wait_status/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Note that tests in this file are run on Linux as well as on platforms using process_unsupported
1+
// Note that tests in this file are run on Linux as well as on platforms using unsupported
22

33
// Test that our emulation exactly matches Linux
44
//

‎library/std/src/sys/pal/unix/process/process_vxworks.rs renamed to ‎library/std/src/sys/process/unix/vxworks.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#![forbid(unsafe_op_in_unsafe_fn)]
22
use libc::{self, RTP_ID, c_char, c_int};
33

4+
use super::common::*;
45
use crate::io::{self, ErrorKind};
56
use crate::num::NonZero;
67
use crate::sys::cvt;
7-
use crate::sys::pal::unix::thread;
8-
use crate::sys::process::process_common::*;
8+
use crate::sys::pal::thread;
99
use crate::{fmt, sys};
1010

1111
////////////////////////////////////////////////////////////////////////////////
@@ -200,7 +200,7 @@ impl ExitStatus {
200200
// true on all actual versions of Unix, is widely assumed, and is specified in SuS
201201
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
202202
// true for a platform pretending to be Unix, the tests (our doctests, and also
203-
// process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
203+
// unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
204204
match NonZero::try_from(self.0) {
205205
Ok(failure) => Err(ExitStatusError(failure)),
206206
Err(_) => Ok(()),

‎library/std/src/sys/pal/windows/process.rs renamed to ‎library/std/src/sys/process/windows.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ mod tests;
55

66
use core::ffi::c_void;
77

8-
use super::api::{self, WinError};
98
use crate::collections::BTreeMap;
109
use crate::env::consts::{EXE_EXTENSION, EXE_SUFFIX};
1110
use crate::ffi::{OsStr, OsString};
12-
use crate::io::{self, Error, ErrorKind};
11+
use crate::io::{self, Error};
1312
use crate::num::NonZero;
1413
use crate::os::windows::ffi::{OsStrExt, OsStringExt};
1514
use crate::os::windows::io::{AsHandle, AsRawHandle, BorrowedHandle, FromRawHandle, IntoRawHandle};
@@ -20,6 +19,8 @@ use crate::sys::args::{self, Arg};
2019
use crate::sys::c::{self, EXIT_FAILURE, EXIT_SUCCESS};
2120
use crate::sys::fs::{File, OpenOptions};
2221
use crate::sys::handle::Handle;
22+
use crate::sys::pal::api::{self, WinError};
23+
use crate::sys::pal::{ensure_no_nuls, fill_utf16_buf};
2324
use crate::sys::pipe::{self, AnonPipe};
2425
use crate::sys::{cvt, path, stdio};
2526
use crate::sys_common::IntoInner;
@@ -142,14 +143,6 @@ impl AsRef<OsStr> for EnvKey {
142143
}
143144
}
144145

145-
pub(crate) fn ensure_no_nuls<T: AsRef<OsStr>>(s: T) -> io::Result<T> {
146-
if s.as_ref().encode_wide().any(|b| b == 0) {
147-
Err(io::const_error!(ErrorKind::InvalidInput, "nul byte found in provided data"))
148-
} else {
149-
Ok(s)
150-
}
151-
}
152-
153146
pub struct Command {
154147
program: OsString,
155148
args: Vec<Arg>,
@@ -279,7 +272,7 @@ impl Command {
279272
let is_batch_file = if path::is_verbatim(&program) {
280273
has_bat_extension(&program[..program.len() - 1])
281274
} else {
282-
super::fill_utf16_buf(
275+
fill_utf16_buf(
283276
|buffer, size| unsafe {
284277
// resolve the path so we can test the final file name.
285278
c::GetFullPathNameW(program.as_ptr(), size, buffer, ptr::null_mut())
@@ -521,15 +514,15 @@ where
521514
// 3 & 4. System paths
522515
// SAFETY: This uses `fill_utf16_buf` to safely call the OS functions.
523516
unsafe {
524-
if let Ok(Some(path)) = super::fill_utf16_buf(
517+
if let Ok(Some(path)) = fill_utf16_buf(
525518
|buf, size| c::GetSystemDirectoryW(buf, size),
526519
|buf| exists(PathBuf::from(OsString::from_wide(buf))),
527520
) {
528521
return Some(path);
529522
}
530523
#[cfg(not(target_vendor = "uwp"))]
531524
{
532-
if let Ok(Some(path)) = super::fill_utf16_buf(
525+
if let Ok(Some(path)) = fill_utf16_buf(
533526
|buf, size| c::GetWindowsDirectoryW(buf, size),
534527
|buf| exists(PathBuf::from(OsString::from_wide(buf))),
535528
) {
@@ -851,10 +844,8 @@ fn make_command_line(argv0: &OsStr, args: &[Arg], force_quotes: bool) -> io::Res
851844

852845
// Get `cmd.exe` for use with bat scripts, encoded as a UTF-16 string.
853846
fn command_prompt() -> io::Result<Vec<u16>> {
854-
let mut system: Vec<u16> = super::fill_utf16_buf(
855-
|buf, size| unsafe { c::GetSystemDirectoryW(buf, size) },
856-
|buf| buf.into(),
857-
)?;
847+
let mut system: Vec<u16> =
848+
fill_utf16_buf(|buf, size| unsafe { c::GetSystemDirectoryW(buf, size) }, |buf| buf.into())?;
858849
system.extend("\\cmd.exe".encode_utf16().chain([0]));
859850
Ok(system)
860851
}

0 commit comments

Comments
 (0)
Please sign in to comment.