diff --git a/Libraries/LibC/spawn.cpp b/Libraries/LibC/spawn.cpp index 026a0fe1df..4c13ccd1e2 100644 --- a/Libraries/LibC/spawn.cpp +++ b/Libraries/LibC/spawn.cpp @@ -147,6 +147,18 @@ int posix_spawnp(pid_t* out_pid, const char* path, const posix_spawn_file_action posix_spawn_child(path, file_actions, attr, argv, envp, execvpe); } +int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t* actions, const char* path) +{ + actions->state->actions.append([path]() { return chdir(path); }); + return 0; +} + +int posix_spawn_file_actions_addfchdir(posix_spawn_file_actions_t* actions, int fd) +{ + actions->state->actions.append([fd]() { return fchdir(fd); }); + return 0; +} + int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t* actions, int fd) { actions->state->actions.append([fd]() { return close(fd); }); diff --git a/Libraries/LibC/spawn.h b/Libraries/LibC/spawn.h index d6d0e03086..87a325e528 100644 --- a/Libraries/LibC/spawn.h +++ b/Libraries/LibC/spawn.h @@ -73,6 +73,8 @@ typedef struct { int posix_spawn(pid_t*, const char*, const posix_spawn_file_actions_t*, const posix_spawnattr_t*, char* const[], char* const[]); int posix_spawnp(pid_t*, const char*, const posix_spawn_file_actions_t*, const posix_spawnattr_t*, char* const[], char* const[]); +int posix_spawn_file_actions_addchdir(posix_spawn_file_actions_t*, const char*); +int posix_spawn_file_actions_addfchdir(posix_spawn_file_actions_t*, int); int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t*, int); int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t*, int old_fd, int new_fd); int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t*, int fd, const char*, int flags, mode_t);