index 2a1ee251f2d7206790f56e536ed2faee0b192e39..6b87e5c9a8c3f1252199227ae21f2368dffd30b0 100755 (executable)
;;
esac
+ case " $LIBOBJS " in
+ *" win32gai_strerror.$ac_objext "* ) ;;
+ *) LIBOBJS="$LIBOBJS win32gai_strerror.$ac_objext"
+ ;;
+esac
+
case " $LIBOBJS " in
*" win32getrusage.$ac_objext "* ) ;;
*) LIBOBJS="$LIBOBJS win32getrusage.$ac_objext"
index 52fd7af446818b9c5f572b02d0cbbfe3a962e160..6e64ece11dad2c41d10d906579d1818d9707946e 100644 (file)
AC_LIBOBJ(win32env)
AC_LIBOBJ(win32error)
AC_LIBOBJ(win32fdatasync)
+ AC_LIBOBJ(win32gai_strerror)
AC_LIBOBJ(win32getrusage)
AC_LIBOBJ(win32link)
AC_LIBOBJ(win32ntdll)
index 0c32c0f7b2ec34e2c50f32928ebaf9c02491fd68..f2b475df5e5e0122f98d8eb009d8e2445c5af4fd 100644 (file)
#define ERROR PGERROR
#endif
+/*
+ * We don't use the Windows gai_strerror[A] function because it is not
+ * thread-safe. We define our own in src/port/win32gai_strerror.c.
+ */
+#undef gai_strerror
+
+extern const char *gai_strerror(int ecode);
+
#endif /* WIN32_SYS_SOCKET_H */
new file mode 100644
(file)
index 0000000..
5b47d17
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * win32gai_strerror.c
+ * Thread-safe gai_strerror() for Windows.
+ *
+ * Portions Copyright (c) 2024, PostgreSQL Global Development Group
+ *
+ * IDENTIFICATION
+ * src/port/win32gai_strerror.c
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#include <sys/socket.h>
+
+/*
+ * Windows has gai_strerrorA(), but it is not thread-safe so we avoid it.
+ *
+ * https://learn.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-gai_strerrora
+ */
+const char *
+gai_strerror(int errcode)
+{
+ switch (errcode)
+ {
+ case EAI_AGAIN:
+ return "Temporary failure in name resolution";
+ case EAI_BADFLAGS:
+ return "Bad value for ai_flags";
+ case EAI_FAIL:
+ return "Non-recoverable failure in name resolution";
+ case EAI_FAMILY:
+ return "ai_family not supported";
+ case EAI_MEMORY:
+ return "Memory allocation failure";
+ case EAI_NONAME:
+ return "Name or service not known";
+ case EAI_SERVICE:
+ return "Servname not supported for ai_socktype";
+ case EAI_SOCKTYPE:
+ return "ai_socktype not supported";
+ default:
+ return "Unknown server error";
+ }
+}