diff options
author | Bruno Haible <bruno@clisp.org> | 2020-05-29 22:28:00 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2020-05-29 22:28:00 +0200 |
commit | 1cc5e34e1339a37387909dd3a9d35538f152d0c6 (patch) | |
tree | 6a53a182b8c752721d20b8b7f98c561e8ce87193 /lib/getaddrinfo.c | |
parent | fb64a78174042189f4d012cbd748d565f021cd69 (diff) | |
download | gnulib-1cc5e34e1339a37387909dd3a9d35538f152d0c6.tar.gz |
Avoid dynamic lookup of Windows API functions when possible.
* lib/getaddrinfo.c (GetProcAddress, getaddrinfo_func,
freeaddrinfo_func, getnameinfo_func, getaddrinfo_ptr, freeaddrinfo_ptr,
getnameinfo_ptr): Don't define in a build for Windows XP or higher.
(use_win32_p): Define differently.
* lib/link.c (GetProcAddress, CreateHardLinkFuncType,
CreateHardLinkFunc, initialized, initialize): Don't define in a build
for Windows XP or higher.
Diffstat (limited to 'lib/getaddrinfo.c')
-rw-r--r-- | lib/getaddrinfo.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c index 99cb709f09..1db9be8698 100644 --- a/lib/getaddrinfo.c +++ b/lib/getaddrinfo.c @@ -86,9 +86,11 @@ freeaddrinfo (struct addrinfo *ai) # ifdef WINDOWS_NATIVE +# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP) + /* Avoid warnings from gcc -Wcast-function-type. */ -# define GetProcAddress \ - (void *) GetProcAddress +# define GetProcAddress \ + (void *) GetProcAddress typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*, const struct addrinfo*, @@ -135,6 +137,29 @@ use_win32_p (void) return 1; } + +# else + +static int +use_win32_p (void) +{ + static int done = 0; + + if (!done) + { + done = 1; + + gl_sockets_startup (SOCKETS_1_1); + } + + return 1; +} + +# define getaddrinfo_ptr getaddrinfo +# define freeaddrinfo_ptr freeaddrinfo +# define getnameinfo_ptr getnameinfo + +# endif # endif static bool @@ -161,6 +186,7 @@ getaddrinfo (const char *restrict nodename, const char *restrict servname, const struct addrinfo *restrict hints, struct addrinfo **restrict res) +#undef getaddrinfo { struct addrinfo *tmp; int port = 0; @@ -362,6 +388,7 @@ getaddrinfo (const char *restrict nodename, /* Free 'addrinfo' structure AI including associated storage. */ void freeaddrinfo (struct addrinfo *ai) +#undef freeaddrinfo { # ifdef WINDOWS_NATIVE if (use_win32_p ()) @@ -388,6 +415,7 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen, char *restrict node, socklen_t nodelen, char *restrict service, socklen_t servicelen, int flags) +#undef getnameinfo { # ifdef WINDOWS_NATIVE if (use_win32_p ()) |