diff --git a/lib/Makefile.inc b/lib/Makefile.inc index a2ca4eebc3..cc7d287625 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -180,6 +180,7 @@ LIB_CFILES = \ krb5.c \ ldap.c \ llist.c \ + macos.c \ md4.c \ md5.c \ memdebug.c \ @@ -316,6 +317,7 @@ LIB_HFILES = \ inet_ntop.h \ inet_pton.h \ llist.h \ + macos.h \ memdebug.h \ mime.h \ mqtt.h \ diff --git a/lib/easy.c b/lib/easy.c index 73a4dc3ef2..d034629b57 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -63,6 +63,7 @@ #include "slist.h" #include "mime.h" #include "amigaos.h" +#include "macos.h" #include "warnless.h" #include "sigpipe.h" #include "vssh/ssh.h" @@ -181,6 +182,11 @@ static CURLcode global_init(long flags, bool memoryfuncs) } #endif + if(Curl_macos_init()) { + DEBUGF(fprintf(stderr, "Error: Curl_macos_init failed\n")); + goto fail; + } + if(Curl_resolver_global_init()) { DEBUGF(fprintf(stderr, "Error: resolver_global_init failed\n")); goto fail; diff --git a/lib/hostip.c b/lib/hostip.c index d721403b72..8b452a8e3b 100644 --- a/lib/hostip.c +++ b/lib/hostip.c @@ -67,10 +67,6 @@ #include "curl_memory.h" #include "memdebug.h" -#if defined(ENABLE_IPV6) && defined(CURL_OSX_CALL_COPYPROXIES) -#include -#endif - #if defined(CURLRES_SYNCH) && \ defined(HAVE_ALARM) && \ defined(SIGALRM) && \ @@ -743,23 +739,6 @@ enum resolve_t Curl_resolv(struct Curl_easy *data, return CURLRESOLV_ERROR; } -#if defined(ENABLE_IPV6) && defined(CURL_OSX_CALL_COPYPROXIES) - { - /* - * The automagic conversion from IPv4 literals to IPv6 literals only - * works if the SCDynamicStoreCopyProxies system function gets called - * first. As Curl currently doesn't support system-wide HTTP proxies, we - * therefore don't use any value this function might return. - * - * This function is only available on a macOS and is not needed for - * IPv4-only builds, hence the conditions above. - */ - CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL); - if(dict) - CFRelease(dict); - } -#endif - #ifndef USE_RESOLVE_ON_IPS /* First check if this is an IPv4 address string */ if(Curl_inet_pton(AF_INET, hostname, &in) > 0) diff --git a/lib/macos.c b/lib/macos.c new file mode 100644 index 0000000000..abebb95a5a --- /dev/null +++ b/lib/macos.c @@ -0,0 +1,62 @@ +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ + +#include "curl_setup.h" + +#if defined(__APPLE__) + +#if defined(TARGET_OS_OSX) && TARGET_OS_OSX + +#include + +#include "macos.h" + +#if defined(ENABLE_IPV6) && defined(CURL_OSX_CALL_COPYPROXIES) +#include +#endif + +CURLcode Curl_macos_init(void) +{ +#if defined(ENABLE_IPV6) && defined(CURL_OSX_CALL_COPYPROXIES) + { + /* + * The automagic conversion from IPv4 literals to IPv6 literals only + * works if the SCDynamicStoreCopyProxies system function gets called + * first. As Curl currently doesn't support system-wide HTTP proxies, we + * therefore don't use any value this function might return. + * + * This function is only available on a macOS and is not needed for + * IPv4-only builds, hence the conditions above. + */ + CFDictionaryRef dict = SCDynamicStoreCopyProxies(NULL); + if(dict) + CFRelease(dict); + } +#endif + return CURLE_OK; +} + +#endif /* TARGET_OS_OSX */ + +#endif /* __APPLE__ */ diff --git a/lib/macos.h b/lib/macos.h new file mode 100644 index 0000000000..4e7e608249 --- /dev/null +++ b/lib/macos.h @@ -0,0 +1,38 @@ +#ifndef HEADER_CURL_MACOS_H +#define HEADER_CURL_MACOS_H +/*************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) Daniel Stenberg, , et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at https://curl.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + * SPDX-License-Identifier: curl + * + ***************************************************************************/ +#include "curl_setup.h" + +#if defined(__APPLE__) && defined(TARGET_OS_OSX) && TARGET_OS_OSX + +CURLcode Curl_macos_init(void); + +#else + +#define Curl_macos_init() CURLE_OK + +#endif + +#endif /* HEADER_CURL_MACOS_H */