AK+Userland: Replace Linux, macOS, and *BSD macros with platform defines

We have such nice platform macros, let's clean up any remnants of manual
__my_platform__ macros in LibCore, LibCompress and AK.
This commit is contained in:
Andrew Kaster 2022-10-09 16:45:59 -06:00 committed by Linus Groh
parent 539fb08551
commit 1d533acbc0
6 changed files with 18 additions and 18 deletions

View file

@ -12,9 +12,9 @@
#ifdef AK_OS_SERENITY
# include <serenity.h>
#elif defined(__linux__) or defined(AK_OS_MACOS)
#elif defined(AK_OS_LINUX) or defined(AK_OS_MACOS)
# include <pthread.h>
#elif defined(__FreeBSD__)
#elif defined(AK_OS_FREEBSD)
# include <pthread.h>
# include <pthread_np.h>
#endif
@ -28,12 +28,12 @@ StackInfo::StackInfo()
perror("get_stack_bounds");
VERIFY_NOT_REACHED();
}
#elif defined(__linux__) or defined(__FreeBSD__)
#elif defined(AK_OS_LINUX) or defined(AK_OS_FREEBSD)
int rc;
pthread_attr_t attr;
pthread_attr_init(&attr);
# ifdef __linux__
# ifdef AK_OS_LINUX
if ((rc = pthread_getattr_np(pthread_self(), &attr)) != 0) {
fprintf(stderr, "pthread_getattr_np: %s\n", strerror(rc));
VERIFY_NOT_REACHED();

View file

@ -9,7 +9,7 @@
// Include the 119.9 KiB of dictionary data from a binary file
extern u8 const brotli_dictionary_data[];
#if defined(__APPLE__)
#if defined(AK_OS_MACOS)
asm(".const_data\n"
".globl _brotli_dictionary_data\n"
"_brotli_dictionary_data:\n");

View file

@ -22,7 +22,7 @@
#endif
// On Linux distros that use glibc `basename` is defined as a macro that expands to `__xpg_basename`, so we undefine it
#if defined(__linux__) && defined(basename)
#if defined(AK_OS_LINUX) && defined(basename)
# undef basename
#endif

View file

@ -17,7 +17,7 @@
#ifdef AK_OS_SERENITY
# include <serenity.h>
#endif
#ifdef __FreeBSD__
#ifdef AK_OS_FREEBSD
# include <sys/ucred.h>
#endif
@ -655,10 +655,10 @@ ErrorOr<pid_t> LocalSocket::peer_pid() const
#ifdef AK_OS_MACOS
pid_t pid;
socklen_t pid_size = sizeof(pid);
#elif defined(__FreeBSD__)
#elif defined(AK_OS_FREEBSD)
struct xucred creds = {};
socklen_t creds_size = sizeof(creds);
#elif defined(__OpenBSD__)
#elif defined(AK_OS_OPENBSD)
struct sockpeercred creds = {};
socklen_t creds_size = sizeof(creds);
#else
@ -669,7 +669,7 @@ ErrorOr<pid_t> LocalSocket::peer_pid() const
#ifdef AK_OS_MACOS
TRY(System::getsockopt(m_helper.fd(), SOL_LOCAL, LOCAL_PEERPID, &pid, &pid_size));
return pid;
#elif defined(__FreeBSD__)
#elif defined(AK_OS_FREEBSD)
TRY(System::getsockopt(m_helper.fd(), SOL_LOCAL, LOCAL_PEERCRED, &creds, &creds_size));
return creds.cr_pid;
#else

View file

@ -31,7 +31,7 @@
# include <serenity.h>
#endif
#if defined(__linux__) && !defined(MFD_CLOEXEC)
#if defined(AK_OS_LINUX) && !defined(MFD_CLOEXEC)
# include <linux/memfd.h>
# include <sys/syscall.h>
@ -41,7 +41,7 @@ static int memfd_create(char const* name, unsigned int flags)
}
#endif
#if defined(__APPLE__)
#if defined(AK_OS_MACOS)
# include <sys/mman.h>
#endif
@ -54,7 +54,7 @@ static int memfd_create(char const* name, unsigned int flags)
namespace Core::System {
#ifndef HOST_NAME_MAX
# ifdef __APPLE__
# ifdef AK_OS_MACOS
# define HOST_NAME_MAX 255
# else
# define HOST_NAME_MAX 64
@ -222,7 +222,7 @@ ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigac
return {};
}
#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__)
#if defined(AK_OS_MACOS) || defined(AK_OS_OPENBSD) || defined(AK_OS_FREEBSD)
ErrorOr<sig_t> signal(int signal, sig_t handler)
#else
ErrorOr<sighandler_t> signal(int signal, sighandler_t handler)
@ -284,7 +284,7 @@ ErrorOr<int> anon_create([[maybe_unused]] size_t size, [[maybe_unused]] int opti
int fd = -1;
#if defined(AK_OS_SERENITY)
fd = ::anon_create(round_up_to_power_of_two(size, PAGE_SIZE), options);
#elif defined(__linux__) || defined(__FreeBSD__)
#elif defined(AK_OS_LINUX) || defined(AK_OS_FREEBSD)
// FIXME: Support more options on Linux.
auto linux_options = ((options & O_CLOEXEC) > 0) ? MFD_CLOEXEC : 0;
fd = memfd_create("", linux_options);
@ -295,7 +295,7 @@ ErrorOr<int> anon_create([[maybe_unused]] size_t size, [[maybe_unused]] int opti
TRY(close(fd));
return Error::from_errno(saved_errno);
}
#elif defined(__APPLE__)
#elif defined(AK_OS_MACOS)
struct timespec time;
clock_gettime(CLOCK_REALTIME, &time);
auto name = String::formatted("/shm-{}{}", (unsigned long)time.tv_sec, (unsigned long)time.tv_nsec);
@ -1033,7 +1033,7 @@ ErrorOr<void> exec(StringView filename, Span<StringView> arguments, SearchInPath
envp[environment->size()] = nullptr;
if (search_in_path == SearchInPath::Yes && !filename.contains('/')) {
# if defined(__APPLE__) || defined(__FreeBSD__)
# if defined(AK_OS_MACOS) || defined(AK_OS_FREEBSD)
// These BSDs don't support execvpe(), so we'll have to manually search the PATH.
ScopedValueRollback errno_rollback(errno);

View file

@ -87,7 +87,7 @@ ErrorOr<int> accept4(int sockfd, struct sockaddr*, socklen_t*, int flags);
#endif
ErrorOr<void> sigaction(int signal, struct sigaction const* action, struct sigaction* old_action);
#if defined(__APPLE__) || defined(__OpenBSD__) || defined(__FreeBSD__)
#if defined(AK_OS_MACOS) || defined(AK_OS_OPENBSD) || defined(AK_OS_FREEBSD)
ErrorOr<sig_t> signal(int signal, sig_t handler);
#else
ErrorOr<sighandler_t> signal(int signal, sighandler_t handler);