From 3fae5f1473fbcde414fba36250f90c44dc78fa42 Mon Sep 17 00:00:00 2001 From: Sergey Date: Tue, 26 Aug 2025 09:46:51 -0700 Subject: [PATCH] osx: fix inconsistent use of the macro TARGET_OS_OSX (#2222) * osx: fix inconsistent use of the macro `TARGET_OS_OSX` Fixed the build error on iOS: ``` httplib.h:3583:3: error: unknown type name 'CFStringRef' 870 | CFStringRef hostname_ref = CFStringCreateWithCString( ``` Note, `TARGET_OS_OSX` is defined but is 0 when `TARGET_OS_IOS` is 1, and vise versa. Hence, `TARGET_OS_MAC` should have been used, that is set to 1 for the both targets. * improve: non-blocking getaddrinfo() for all mac target variants `TARGET_OS_MAC` should have been used, that is set to 1 for all other targets: OSX, IPHONE (IOS, TV, WATCH, VISION, BRIDGE), SIMULATOR, DRIVERKIT. --- httplib.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/httplib.h b/httplib.h index 25e1b2f..a8dd905 100644 --- a/httplib.h +++ b/httplib.h @@ -308,7 +308,7 @@ using socket_t = int; #if defined(CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO) || \ defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) -#if TARGET_OS_OSX +#if TARGET_OS_MAC #include #include #endif @@ -332,7 +332,7 @@ using socket_t = int; #endif // _WIN32 #if defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) -#if TARGET_OS_OSX +#if TARGET_OS_MAC #include #endif #endif // CPPHTTPLIB_USE_NON_BLOCKING_GETADDRINFO @@ -3578,7 +3578,7 @@ inline int getaddrinfo_with_timeout(const char *node, const char *service, } return ret; -#elif defined(TARGET_OS_OSX) +#elif TARGET_OS_MAC // macOS implementation using CFHost API for asynchronous DNS resolution CFStringRef hostname_ref = CFStringCreateWithCString( kCFAllocatorDefault, node, kCFStringEncodingUTF8); @@ -6258,8 +6258,7 @@ inline bool load_system_certs_on_windows(X509_STORE *store) { return result; } -#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && \ - defined(TARGET_OS_OSX) +#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && TARGET_OS_MAC template using CFObjectPtr = std::unique_ptr::type, void (*)(CFTypeRef)>; @@ -11008,8 +11007,7 @@ inline bool SSLClient::load_certs() { #ifdef _WIN32 loaded = detail::load_system_certs_on_windows(SSL_CTX_get_cert_store(ctx_)); -#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && \ - defined(TARGET_OS_OSX) +#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && TARGET_OS_MAC loaded = detail::load_system_certs_on_macos(SSL_CTX_get_cert_store(ctx_)); #endif // _WIN32 if (!loaded) { SSL_CTX_set_default_verify_paths(ctx_); }