From 3a11213b686199dd14ce68b7b13196e0deebb485 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 21 Mar 2019 11:51:37 +0000 Subject: [PATCH] =?UTF-8?q?gresolver:=20Don=E2=80=99t=20use=20gai=5Fstrerr?= =?UTF-8?q?or()=20on=20Windows,=20as=20it=20isn=E2=80=99t=20threadsafe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead, use WSAGetLastError(). Signed-off-by: Philip Withnall Helps: #1732 --- gio/gresolver.c | 12 +++++++++++- gio/gthreadedresolver.c | 23 +++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/gio/gresolver.c b/gio/gresolver.c index 6a33634c5..607bd830a 100644 --- a/gio/gresolver.c +++ b/gio/gresolver.c @@ -340,9 +340,19 @@ handle_ip_address (const char *hostname, if (inet_aton (hostname, &ip4addr)) #endif { +#ifdef G_OS_WIN32 + gchar *error_message = g_win32_error_message (WSAHOST_NOT_FOUND); +#else + const gchar *error_message = gai_strerror (EAI_NONAME); +#endif g_set_error (error, G_RESOLVER_ERROR, G_RESOLVER_ERROR_NOT_FOUND, _("Error resolving “%s”: %s"), - hostname, gai_strerror (EAI_NONAME)); + hostname, error_message); + +#ifdef G_OS_WIN32 + g_free (error_message); +#endif + return TRUE; } diff --git a/gio/gthreadedresolver.c b/gio/gthreadedresolver.c index 9b7c396a1..46bea14f0 100644 --- a/gio/gthreadedresolver.c +++ b/gio/gthreadedresolver.c @@ -154,11 +154,21 @@ do_lookup_by_name (GTask *task, } else { +#ifdef G_OS_WIN32 + gchar *error_message = g_win32_error_message (WSAGetLastError ()); +#else + const gchar *error_message = gai_strerror (retval); +#endif + g_task_return_new_error (task, G_RESOLVER_ERROR, g_resolver_error_from_addrinfo_error (retval), _("Error resolving “%s”: %s"), - hostname, gai_strerror (retval)); + hostname, error_message); + +#ifdef G_OS_WIN32 + g_free (error_message); +#endif } if (res) @@ -310,14 +320,23 @@ do_lookup_by_address (GTask *task, { gchar *phys; +#ifdef G_OS_WIN32 + gchar *error_message = g_win32_error_message (WSAGetLastError ()); +#else + const gchar *error_message = gai_strerror (retval); +#endif + phys = g_inet_address_to_string (address); g_task_return_new_error (task, G_RESOLVER_ERROR, g_resolver_error_from_addrinfo_error (retval), _("Error reverse-resolving “%s”: %s"), phys ? phys : "(unknown)", - gai_strerror (retval)); + error_message); g_free (phys); +#ifdef G_OS_WIN32 + g_free (error_message); +#endif } }