diff --git a/Userland/Libraries/LibCore/Process.cpp b/Userland/Libraries/LibCore/Process.cpp index 285973462c..6774c67e61 100644 --- a/Userland/Libraries/LibCore/Process.cpp +++ b/Userland/Libraries/LibCore/Process.cpp @@ -21,20 +21,6 @@ # include #endif -#if defined(AK_OS_MACOS) -# include -#endif - -static char** environment() -{ -#if defined(AK_OS_MACOS) - return *_NSGetEnviron(); -#else - extern char** environ; - return environ; -#endif -} - namespace Core { struct ArgvList { @@ -77,11 +63,11 @@ struct ArgvList { if (!m_working_directory.is_empty()) posix_spawn_file_actions_addchdir(&spawn_actions, m_working_directory.characters()); - auto pid = TRY(System::posix_spawn(m_path.view(), &spawn_actions, nullptr, const_cast(get().data()), environment())); + auto pid = TRY(System::posix_spawn(m_path.view(), &spawn_actions, nullptr, const_cast(get().data()), System::environment())); if (keep_as_child == Process::KeepAsChild::No) TRY(System::disown(pid)); #else - auto pid = TRY(System::posix_spawn(m_path.view(), nullptr, nullptr, const_cast(get().data()), environment())); + auto pid = TRY(System::posix_spawn(m_path.view(), nullptr, nullptr, const_cast(get().data()), System::environment())); // FIXME: Support keep_as_child outside Serenity. (void)keep_as_child; #endif diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index c26bc0ace1..feb1dee6a2 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -43,7 +43,10 @@ static int memfd_create(char const* name, unsigned int flags) #endif #if defined(AK_OS_MACOS) +# include # include +#else +extern char** environ; #endif #define HANDLE_SYSCALL_RETURN_VALUE(syscall_name, rc, success_value) \ @@ -1714,4 +1717,13 @@ ErrorOr resolve_executable_from_environment(StringView filename, int fla return Error::from_errno(ENOENT); } +char** environment() +{ +#if defined(AK_OS_MACOS) + return *_NSGetEnviron(); +#else + return environ; +#endif +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index 9527e50af7..41f971a8e8 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -271,4 +271,6 @@ ErrorOr posix_fallocate(int fd, off_t offset, off_t length); ErrorOr resolve_executable_from_environment(StringView filename, int flags = 0); +char** environment(); + }