From 2261ed28f753eae0f9b4a1e6b86c34b0fca59231 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 16 Jul 2025 12:32:24 +0900 Subject: [PATCH] lib-socket: implement gai_strerror cf. https://pubs.opengroup.org/onlinepubs/9799919799/functions/gai_strerror.html --- .../lib-socket/inc/wasi_socket_ext.h | 3 +++ .../lib-socket/src/wasi/wasi_socket_ext.c | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h b/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h index 98ccc78c11..2bad1ebed9 100644 --- a/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h +++ b/core/iwasm/libraries/lib-socket/inc/wasi_socket_ext.h @@ -219,6 +219,9 @@ getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, void freeaddrinfo(struct addrinfo *res); + +const char * +gai_strerror(int code); #endif /** diff --git a/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c b/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c index f016bdebca..8f80e0bbbc 100644 --- a/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c +++ b/core/iwasm/libraries/lib-socket/src/wasi/wasi_socket_ext.c @@ -590,6 +590,28 @@ freeaddrinfo(struct addrinfo *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 time_us_to_timeval(uint64_t time_us) {