From 6c6b2442edabe9e3f77d29aacd6681bc3fa16d9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Mon, 19 Feb 2024 13:43:49 +0100 Subject: [PATCH] build: Replace MAC_OSX macro with existing __APPLE__ Adopting `__APPLE__` aligns our project with broader industry practices, including those in prominent projects such as the Linux kernel (and even our own code). See: https://sourceforge.net/p/predef/wiki/OperatingSystems/#macos --- CMakeLists.txt | 5 +---- src/common/args.cpp | 4 ++-- src/common/system.cpp | 2 +- src/random.cpp | 4 ++-- src/util/fs_helpers.cpp | 4 ++-- src/util/threadnames.cpp | 2 +- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index edc47106378..e68af79b515 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -324,10 +324,7 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux" AND CMAKE_SIZEOF_VOID_P EQUAL 4) endif() if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - target_compile_definitions(core_interface INTERFACE - MAC_OSX - OBJC_OLD_DISPATCH_PROTOTYPES=0 - ) + target_compile_definitions(core_interface INTERFACE OBJC_OLD_DISPATCH_PROTOTYPES=0) # These flags are specific to ld64, and may cause issues with other linkers. # For example: GNU ld will interpret -dead_strip as -de and then try and use # "ad_strip" as the symbol for the entry point. diff --git a/src/common/args.cpp b/src/common/args.cpp index f59d2b8f0fc..f8283b12885 100644 --- a/src/common/args.cpp +++ b/src/common/args.cpp @@ -184,7 +184,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin for (int i = 1; i < argc; i++) { std::string key(argv[i]); -#ifdef MAC_OSX +#ifdef __APPLE__ // At the first time when a user gets the "App downloaded from the // internet" warning, and clicks the Open button, macOS passes // a unique process serial number (PSN) as -psn_... command-line @@ -741,7 +741,7 @@ fs::path GetDefaultDataDir() pathRet = fs::path("/"); else pathRet = fs::path(pszHome); -#ifdef MAC_OSX +#ifdef __APPLE__ // macOS return pathRet / "Library/Application Support/Bitcoin"; #else diff --git a/src/common/system.cpp b/src/common/system.cpp index 6a9463a0a51..7af792db44c 100644 --- a/src/common/system.cpp +++ b/src/common/system.cpp @@ -70,7 +70,7 @@ void SetupEnvironment() #endif // On most POSIX systems (e.g. Linux, but not BSD) the environment's locale // may be invalid, in which case the "C.UTF-8" locale is used as fallback. -#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) +#if !defined(WIN32) && !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) try { std::locale(""); // Raises a runtime error if current locale is invalid } catch (const std::runtime_error&) { diff --git a/src/random.cpp b/src/random.cpp index 163112585ac..55d5f388724 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -34,7 +34,7 @@ #include #endif -#if defined(HAVE_GETRANDOM) || (defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX)) +#if defined(HAVE_GETRANDOM) || (defined(HAVE_GETENTROPY_RAND) && defined(__APPLE__)) #include #endif @@ -387,7 +387,7 @@ void GetOSRand(unsigned char *ent32) The function call is always successful. */ arc4random_buf(ent32, NUM_OS_RANDOM_BYTES); -#elif defined(HAVE_GETENTROPY_RAND) && defined(MAC_OSX) +#elif defined(HAVE_GETENTROPY_RAND) && defined(__APPLE__) if (getentropy(ent32, NUM_OS_RANDOM_BYTES) != 0) { RandFailure(); } diff --git a/src/util/fs_helpers.cpp b/src/util/fs_helpers.cpp index 7ac7b829d8e..4d06afe1442 100644 --- a/src/util/fs_helpers.cpp +++ b/src/util/fs_helpers.cpp @@ -117,7 +117,7 @@ bool FileCommit(FILE* file) LogPrintf("FlushFileBuffers failed: %s\n", Win32ErrorString(GetLastError())); return false; } -#elif defined(MAC_OSX) && defined(F_FULLFSYNC) +#elif defined(__APPLE__) && defined(F_FULLFSYNC) if (fcntl(fileno(file), F_FULLFSYNC, 0) == -1) { // Manpage says "value other than -1" is returned on success LogPrintf("fcntl F_FULLFSYNC failed: %s\n", SysErrorString(errno)); return false; @@ -195,7 +195,7 @@ void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length) nFileSize.u.HighPart = nEndPos >> 32; SetFilePointerEx(hFile, nFileSize, 0, FILE_BEGIN); SetEndOfFile(hFile); -#elif defined(MAC_OSX) +#elif defined(__APPLE__) // OSX specific version // NOTE: Contrary to other OS versions, the OSX version assumes that // NOTE: offset is the size of the file. diff --git a/src/util/threadnames.cpp b/src/util/threadnames.cpp index 37c5b8f6172..032572fb53c 100644 --- a/src/util/threadnames.cpp +++ b/src/util/threadnames.cpp @@ -29,7 +29,7 @@ static void SetThreadName(const char* name) ::prctl(PR_SET_NAME, name, 0, 0, 0); #elif (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)) pthread_set_name_np(pthread_self(), name); -#elif defined(MAC_OSX) +#elif defined(__APPLE__) pthread_setname_np(name); #else // Prevent warnings for unused parameters...