mirror of
https://github.com/postgres/postgres.git
synced 2025-05-08 07:21:33 +03:00
Commit 5579388d removed code that supplied a fallback implementation of getaddrinfo(), which was dead code on modern systems. One tiny piece of the removed code was still doing something useful on Windows, though: that OS's own gai_strerror()/gai_strerrorA() function returns a pointer to a static buffer that it overwrites each time, so it's not thread-safe. In rare circumstances, a multi-threaded client program could get an incorrect or corrupted error message. Restore the replacement gai_strerror() function, though now that it's only for Windows we can put it into a win32-specific file and cut it down to the errors that Windows documents. The error messages here are taken from FreeBSD, because Windows' own messages seemed too verbose. Back-patch to 16. Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Discussion: https://postgr.es/m/CA%2BhUKGKz%2BF9d2PTiXwfYV7qJw%2BWg2jzACgSDgPizUw7UG%3Di58A%40mail.gmail.com
46 lines
1.1 KiB
C
46 lines
1.1 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* 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";
|
|
}
|
|
}
|