From 37be90b1f79b45ae2761c6e276a7f9895bdc8363 Mon Sep 17 00:00:00 2001 From: SirLynix Date: Tue, 23 Jan 2024 17:32:58 +0100 Subject: [PATCH] Fix compilation on macOS --- src/Nazara/Core/Posix/PosixUtils.cpp | 17 +++++++++++++++++ src/Nazara/Core/Posix/ProcessImpl.cpp | 1 + 2 files changed, 18 insertions(+) diff --git a/src/Nazara/Core/Posix/PosixUtils.cpp b/src/Nazara/Core/Posix/PosixUtils.cpp index 69cf41651..89cb12038 100644 --- a/src/Nazara/Core/Posix/PosixUtils.cpp +++ b/src/Nazara/Core/Posix/PosixUtils.cpp @@ -59,8 +59,25 @@ namespace Nz::PlatformImpl m_writeFd(-1) { int fds[2]; +#if defined(NAZARA_PLATFORM_LINUX) || defined(NAZARA_PLATFORM_ANDROID) if (::pipe2(fds, flags & O_CLOEXEC) != 0) return; +#else + if (::pipe(fds) != 0) + return; + + auto SetCloseOnExec = [](int fd) + { + int flags = ::fcntl(fd, F_GETFD, 0); + if (flags < 0) + return flags; // error + + return ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); + }; + + SetCloseOnExec(fds[0]); + SetCloseOnExec(fds[1]); +#endif m_readFd = fds[0]; m_writeFd = fds[1]; diff --git a/src/Nazara/Core/Posix/ProcessImpl.cpp b/src/Nazara/Core/Posix/ProcessImpl.cpp index 2035c9886..a10c036ee 100644 --- a/src/Nazara/Core/Posix/ProcessImpl.cpp +++ b/src/Nazara/Core/Posix/ProcessImpl.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include