* Correctly determine argv[0]

- If the function called is `posix_spawnp`, and the passed program name **does not** contain a slash, the path is used unmodified, and the path to the directory containing the program on $PATH is prepended to the program's path and assigned to `argv[0]. If the program name **does** contain a slash, the path is absolutised relative to CWD, and assigned to argv[0]

    - If the function called is `posix_spawn`, the behaviour is as described above in the case where path contains a slash

* Add initial tests
This commit is contained in:
R Aadarsh
2026-06-07 10:10:02 +05:30
parent f59e292744
commit ad151e0de8
11 changed files with 106 additions and 104 deletions
+4 -1
View File
@@ -47,6 +47,7 @@ unsafe fn spawn(
ERRNO.get()
);
let mut path_path = None;
if use_path {
let path = unsafe { getenv(c"PATH".as_ptr()) };
let path_env = unsafe { CStr::from_nullable_ptr(path).unwrap().to_str().unwrap() };
@@ -70,10 +71,12 @@ unsafe fn spawn(
CStr::from_ptr(dir_ent.d_name.as_ptr() as *const c_char)
.to_str()
.unwrap()
.to_string()
};
if dir_ent_name == program {
flag = true;
program = format!("{}/{}", path_element, program);
path_path = Some(path_element.to_string());
break 'a;
}
}
@@ -93,7 +96,7 @@ unsafe fn spawn(
spawn_attr,
argv,
envp,
use_path,
path_path,
)
.map(|v| {
if let Some(pid) = pid {