Forráskód Böngészése

lib-socket: implement gai_strerror (#4508)

cf. https://pubs.opengroup.org/onlinepubs/9799919799/functions/gai_strerror.html
YAMAMOTO Takashi 7 hónapja
szülő
commit
f34d28cfbc

+ 3 - 0
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
 
 /**

+ 22 - 0
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)
 {