From 9a4ee9aa1a6d947c720b5a550d1d5e81e715ba98 Mon Sep 17 00:00:00 2001 From: Marcin Gasperowicz Date: Fri, 29 May 2020 22:22:01 +0200 Subject: [PATCH] Lagom: Adjust AK, LibCore and LibTLS to build on MacOS --- AK/Random.h | 6 +++++- Libraries/LibCore/LocalServer.cpp | 6 ++++-- Libraries/LibTLS/TLSv12.cpp | 10 ++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/AK/Random.h b/AK/Random.h index 8c22ab9387c..2041f073598 100644 --- a/AK/Random.h +++ b/AK/Random.h @@ -37,13 +37,17 @@ # include #endif +#if defined(__APPLE__) +# include +#endif + namespace AK { inline void fill_with_random(void* buffer, size_t length) { #if defined(__serenity__) arc4random_buf(buffer, length); -#elif defined(__linux__) +#elif defined(__linux__) or defined(__APPLE__) int rc = getentropy(buffer, length); (void)rc; #endif diff --git a/Libraries/LibCore/LocalServer.cpp b/Libraries/LibCore/LocalServer.cpp index bd1c1e1a2ef..a8ac87b961a 100644 --- a/Libraries/LibCore/LocalServer.cpp +++ b/Libraries/LibCore/LocalServer.cpp @@ -31,8 +31,9 @@ #include #include #include + #ifndef SOCK_NONBLOCK -#include +# include #endif namespace Core { @@ -111,12 +112,13 @@ bool LocalServer::listen(const String& address) fcntl(m_fd, F_SETFD, FD_CLOEXEC); #endif ASSERT(m_fd >= 0); - +#ifndef __APPLE__ rc = fchmod(m_fd, 0600); if (rc < 0) { perror("fchmod"); ASSERT_NOT_REACHED(); } +#endif auto socket_address = SocketAddress::local(address); auto un = socket_address.to_sockaddr_un(); diff --git a/Libraries/LibTLS/TLSv12.cpp b/Libraries/LibTLS/TLSv12.cpp index 04e88ee121c..f87e73481bb 100644 --- a/Libraries/LibTLS/TLSv12.cpp +++ b/Libraries/LibTLS/TLSv12.cpp @@ -30,6 +30,10 @@ #include #include +#ifndef SOCK_NONBLOCK +# include +#endif + //#define TLS_DEBUG namespace { @@ -701,7 +705,13 @@ TLSv12::TLSv12(Core::Object* parent, Version version) m_context.version = version; m_context.is_server = false; m_context.tls_buffer = ByteBuffer::create_uninitialized(0); +#ifdef SOCK_NONBLOCK int fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); +#else + int fd = socket(AF_INET, SOCK_STREAM, 0); + int option = 1; + ioctl(fd, FIONBIO, &option); +#endif if (fd < 0) { set_error(errno); } else {