From 0295d7933930ac737664374cabea3d4b1f742429 Mon Sep 17 00:00:00 2001 From: MacDue Date: Wed, 11 May 2022 20:24:39 +0100 Subject: [PATCH] LibCore: Add posix_spawn() wrapper to Core::System --- Userland/Libraries/LibCore/System.cpp | 16 +++++++++++++--- Userland/Libraries/LibCore/System.h | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 92a6eaaee0..ce810cd925 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -661,14 +661,24 @@ 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[]) +static ALWAYS_INLINE ErrorOr posix_spawn_wrapper(StringView path, posix_spawn_file_actions_t const* file_actions, posix_spawnattr_t const* attr, char* const arguments[], char* const envp[], StringView function_name, decltype(::posix_spawn) spawn_function) { 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); + if ((errno = spawn_function(&child_pid, path.to_string().characters(), file_actions, attr, arguments, envp))) + return Error::from_syscall(function_name, -errno); return child_pid; } +ErrorOr posix_spawn(StringView path, posix_spawn_file_actions_t const* file_actions, posix_spawnattr_t const* attr, char* const arguments[], char* const envp[]) +{ + return posix_spawn_wrapper(path, file_actions, attr, arguments, envp, "posix_spawn"sv, ::posix_spawn); +} + +ErrorOr posix_spawnp(StringView path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]) +{ + return posix_spawn_wrapper(path, file_actions, attr, arguments, envp, "posix_spawnp"sv, ::posix_spawnp); +} + ErrorOr lseek(int fd, off_t offset, int whence) { off_t rc = ::lseek(fd, offset, whence); diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 49a0a2d288..75364d8b1d 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -97,7 +97,8 @@ ErrorOr> getgrnam(StringView name); ErrorOr> getpwuid(uid_t); ErrorOr> getgrgid(gid_t); 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[]); +ErrorOr posix_spawn(StringView path, posix_spawn_file_actions_t const* file_actions, posix_spawnattr_t const* attr, char* const arguments[], char* const envp[]); +ErrorOr posix_spawnp(StringView path, posix_spawn_file_actions_t* const file_actions, posix_spawnattr_t* const attr, char* const arguments[], char* const envp[]); ErrorOr lseek(int fd, off_t, int whence); struct WaitPidResult {