Skip to content

Commit

Permalink
AK+Userland: Replace Linux, macOS, and *BSD macros with platform defines
Browse files Browse the repository at this point in the history
We have such nice platform macros, let's clean up any remnants of manual
__my_platform__ macros in LibCore, LibCompress and AK.
  • Loading branch information
ADKaster authored and linusg committed Oct 10, 2022
1 parent 539fb08 commit 1d533ac
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions AK/StackInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibCompress/BrotliDictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibCore/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions Userland/Libraries/LibCore/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifdef AK_OS_SERENITY
# include <serenity.h>
#endif
#ifdef __FreeBSD__
#ifdef AK_OS_FREEBSD
# include <sys/ucred.h>
#endif

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions Userland/Libraries/LibCore/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibCore/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1d533ac

Please sign in to comment.