summaryrefslogtreecommitdiff
path: root/userland/libc/netdb/gai_strerror.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-12-16 20:26:20 +0100
committerAnton Kling <anton@kling.gg>2024-12-16 20:29:43 +0100
commit9501c3f45b9b5d3b2cef5e78c83c362dbe6295a5 (patch)
tree023d97e2e476e3e197c840d136e8c6cf8449cded /userland/libc/netdb/gai_strerror.c
parent3f8324fde2128c3308f957891262d3372fb57ebf (diff)
libc: Add gai_strerror
Diffstat (limited to 'userland/libc/netdb/gai_strerror.c')
-rw-r--r--userland/libc/netdb/gai_strerror.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/userland/libc/netdb/gai_strerror.c b/userland/libc/netdb/gai_strerror.c
new file mode 100644
index 0000000..81457cb
--- /dev/null
+++ b/userland/libc/netdb/gai_strerror.c
@@ -0,0 +1,36 @@
+#include <assert.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+const char *gai_strerror(int errcode) {
+ switch (errcode) {
+ case EAI_AGAIN:
+ return "The name could not be resolved at this time. Future attempts may "
+ "succeed.";
+ case EAI_BADFLAGS:
+ return "The flags had an invalid value.";
+ case EAI_FAIL:
+ return "A non-recoverable error occurred.";
+ case EAI_FAMILY:
+ return "The address family was not recognized or the address length was "
+ "invalid for the specified family.";
+ case EAI_MEMORY:
+ return "There was a memory allocation failure.";
+ case EAI_NONAME:
+ return "The name does not resolve for the supplied parameters. NI_NAMEREQD "
+ "is set and the host's name cannot be located, or both nodename and "
+ "servname were null.";
+ case EAI_SERVICE:
+ return "The service passed was not recognized for the specified socket "
+ "type.";
+ case EAI_SOCKTYPE:
+ return "The intended socket type was not recognized.";
+ case EAI_SYSTEM:
+ return "A system error occurred. The error code can be found in errno.";
+ case EAI_OVERFLOW:
+ return "An argument buffer overflowed.";
+ default:
+ return "Invalid gai error code, no error string found.";
+ }
+}