Skip to content

Commit 1c0f88f

Browse files
authored
refactor: change posix_spawn path arg to use NixPath (#2596)
* refactor: change posix_spawn path arg to use NixPath * style: fmt
1 parent 0c40b8d commit 1c0f88f

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/spawn.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -361,27 +361,34 @@ unsafe fn to_exec_array<S: AsRef<CStr>>(args: &[S]) -> Vec<*mut libc::c_char> {
361361

362362
/// Create a new child process from the specified process image. See
363363
/// [posix_spawn](https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn.html).
364-
pub fn posix_spawn<SA: AsRef<CStr>, SE: AsRef<CStr>>(
365-
path: &CStr,
364+
pub fn posix_spawn<P, SA, SE>(
365+
path: &P,
366366
file_actions: &PosixSpawnFileActions,
367367
attr: &PosixSpawnAttr,
368368
args: &[SA],
369369
envp: &[SE],
370-
) -> Result<Pid> {
370+
) -> Result<Pid>
371+
where
372+
P: NixPath + ?Sized,
373+
SA: AsRef<CStr>,
374+
SE: AsRef<CStr>,
375+
{
371376
let mut pid = 0;
372377

373378
let ret = unsafe {
374379
let args_p = to_exec_array(args);
375380
let env_p = to_exec_array(envp);
376381

377-
libc::posix_spawn(
378-
&mut pid as *mut libc::pid_t,
379-
path.as_ptr(),
380-
&file_actions.fa as *const libc::posix_spawn_file_actions_t,
381-
&attr.attr as *const libc::posix_spawnattr_t,
382-
args_p.as_ptr(),
383-
env_p.as_ptr(),
384-
)
382+
path.with_nix_path(|c_str| {
383+
libc::posix_spawn(
384+
&mut pid as *mut libc::pid_t,
385+
c_str.as_ptr(),
386+
&file_actions.fa as *const libc::posix_spawn_file_actions_t,
387+
&attr.attr as *const libc::posix_spawnattr_t,
388+
args_p.as_ptr(),
389+
env_p.as_ptr(),
390+
)
391+
})?
385392
};
386393

387394
if ret != 0 {

0 commit comments

Comments
 (0)