lib-socket: implement gai_strerror (#4508)

cf. https://pubs.opengroup.org/onlinepubs/9799919799/functions/gai_strerror.html
This commit is contained in:
YAMAMOTO Takashi 2025-07-29 12:12:27 +09:00 committed by GitHub
parent 224b426d70
commit f34d28cfbc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View File

@ -219,6 +219,9 @@ getaddrinfo(const char *node, const char *service, const struct addrinfo *hints,
void void
freeaddrinfo(struct addrinfo *res); freeaddrinfo(struct addrinfo *res);
const char *
gai_strerror(int code);
#endif #endif
/** /**

View File

@ -590,6 +590,28 @@ freeaddrinfo(struct addrinfo *res)
free(res); free(res);
} }
const char *
gai_strerror(int code)
{
switch (code) {
#define ERR(a) \
case a: \
return #a
ERR(EAI_AGAIN);
ERR(EAI_BADFLAGS);
ERR(EAI_FAIL);
ERR(EAI_FAMILY);
ERR(EAI_MEMORY);
ERR(EAI_NONAME);
ERR(EAI_OVERFLOW);
ERR(EAI_SERVICE);
ERR(EAI_SOCKTYPE);
ERR(EAI_SYSTEM);
#undef ERR
}
return "Unknown error";
}
static struct timeval static struct timeval
time_us_to_timeval(uint64_t time_us) time_us_to_timeval(uint64_t time_us)
{ {