diff options
author | Viktor Szakats <commit@vsz.me> | 2022-11-01 22:40:36 +0000 |
---|---|---|
committer | Viktor Szakats <commit@vsz.me> | 2022-11-01 22:40:36 +0000 |
commit | edae6c66c7444a59224a56c360d8fa5e4a7b86db (patch) | |
tree | 4ae139357599b9ef97dd5f83e5a802330781d336 /lib/hostip4.c | |
parent | b563a92cd6797ec40d7cd73d51f9c31e637463f4 (diff) | |
download | curl-edae6c66c7444a59224a56c360d8fa5e4a7b86db.tar.gz |
lib: sync guard for Curl_getaddrinfo_ex() definition and use
`Curl_getaddrinfo_ex()` gets _defined_ with `HAVE_GETADDRINFO` set. But,
`hostip4.c` _used_ it with `HAVE_GETADDRINFO_THREADSAFE` set alone. It
meant a build with the latter, but without the former flag could result
in calling this function but not defining it, and failing to link.
Patch this by adding an extra check for `HAVE_GETATTRINFO` around the
call.
Before this patch, build systems prevented this condition. Now they
don't need to.
While here, simplify the related CMake logic on Windows by setting
`HAVE_GETADDRINFO_THREADSAFE` to the detection result of
`HAVE_GETADDRINFO`. This expresses the following intent clearer than
the previous patch and keeps the logic in a single block of code:
When we have `getaddrinfo()` on Windows, it's always threadsafe.
Follow-up to 67d88626d44ec04b9e11dca4cfbf62cd29fe9781
Reviewed-by: Jay Satiro
Closes #9734
Diffstat (limited to 'lib/hostip4.c')
-rw-r--r-- | lib/hostip4.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/hostip4.c b/lib/hostip4.c index b0280cd09..109bd1e5e 100644 --- a/lib/hostip4.c +++ b/lib/hostip4.c @@ -121,14 +121,15 @@ struct Curl_addrinfo *Curl_getaddrinfo(struct Curl_easy *data, struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, int port) { -#if !defined(HAVE_GETADDRINFO_THREADSAFE) && defined(HAVE_GETHOSTBYNAME_R_3) +#if !(defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE)) && \ + defined(HAVE_GETHOSTBYNAME_R_3) int res; #endif struct Curl_addrinfo *ai = NULL; struct hostent *h = NULL; struct hostent *buf = NULL; -#if defined(HAVE_GETADDRINFO_THREADSAFE) +#if defined(HAVE_GETADDRINFO) && defined(HAVE_GETADDRINFO_THREADSAFE) struct addrinfo hints; char sbuf[12]; char *sbufptr = NULL; @@ -276,14 +277,16 @@ struct Curl_addrinfo *Curl_ipv4_resolve_r(const char *hostname, h = NULL; /* set return code to NULL */ free(buf); } -#else /* HAVE_GETADDRINFO_THREADSAFE || HAVE_GETHOSTBYNAME_R */ +#else /* (HAVE_GETADDRINFO && HAVE_GETADDRINFO_THREADSAFE) || + HAVE_GETHOSTBYNAME_R */ /* * Here is code for platforms that don't have a thread safe * getaddrinfo() nor gethostbyname_r() function or for which * gethostbyname() is the preferred one. */ h = gethostbyname((void *)hostname); -#endif /* HAVE_GETADDRINFO_THREADSAFE || HAVE_GETHOSTBYNAME_R */ +#endif /* (HAVE_GETADDRINFO && HAVE_GETADDRINFO_THREADSAFE) || + HAVE_GETHOSTBYNAME_R */ if(h) { ai = Curl_he2ai(h, port); |