From 123e49994d05c105421db10baa3a109bb57d0fa7 Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Mon, 13 Dec 2021 18:38:48 +0100 Subject: [PATCH] LibCore: Add posix_spawnp() wrapper that return ErrorOr --- Userland/Libraries/LibCore/System.cpp | 8 ++++++++ Userland/Libraries/LibCore/System.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index a76d2a6da9..54a04e9002 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -372,4 +372,12 @@ ErrorOr clock_settime(clockid_t clock_id, struct timespec* ts) #endif } +ErrorOr posix_spawnp(StringView const path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]) +{ + pid_t child_pid; + if ((errno = ::posix_spawnp(&child_pid, path.to_string().characters(), file_actions, attr, arguments, envp))) + return Error::from_syscall("posix_spawnp"sv, -errno); + return child_pid; +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index b04f89ae7a..e9d8dd8b8e 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -51,5 +52,6 @@ ErrorOr chown(StringView pathname, uid_t uid, gid_t gid); ErrorOr getpwnam(StringView name); ErrorOr getgrnam(StringView name); ErrorOr clock_settime(clockid_t clock_id, struct timespec* ts); +ErrorOr posix_spawnp(StringView const path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]); }