]> git.corax.cc Git - corax/commitdiff
libc: Add strerror() implementation
authorMatthias Kruk <m@m10k.eu>
Sat, 15 Aug 2020 06:15:40 +0000 (15:15 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 15 Aug 2020 06:15:40 +0000 (15:15 +0900)
include/string.h
libc/string.c

index 9697603c0123633e9a36b9eaf12d641a256faf4e..536b54b7eb82d617d91a5b584a9f2a24fc06caed 100644 (file)
@@ -6,5 +6,6 @@
 void* memset(void *dst, int val, u32_t n);
 void* memcpy(void *dst, const void *src, u32_t n);
 size_t strlen(const char*);
+const char *strerror(int);
 
 #endif /* _STRING_H */
index a8e548a69cdbcfe92f3fad4928faa5565cd871ae..566a2224dae2e2418a9daa1bda1ee7755dcf2c0b 100644 (file)
@@ -1,4 +1,5 @@
 #include <sys/types.h>
+#include <errno.h>
 
 size_t strlen(const char *s)
 {
@@ -22,3 +23,39 @@ void *memset(void *s, int c, size_t n)
 
        return(s);
 }
+
+static const char *_errno_str[] = {
+       "SUCCESS",
+       "EINVAL",
+       "ENOSYS",
+       "EALREADY",
+       "EAGAIN",
+       "ENOMEM",
+       "EFAULT",
+       "EAFNOSUPPORT",
+       "EMFILE",
+       "EBADF",
+       "ENFILE",
+       "EADDRNOTAVAIL",
+       "ENOTSUP",
+       "EOPNOTSUPP",
+       "ENOENT",
+       "EPERM",
+       "EACCES",
+       "ERANGE",
+       "EBADFD",
+       "EBUSY",
+       "EINTR",
+       "EOVERFLOW",
+       "ECONNREFUSED",
+       NULL
+};
+
+const char *strerror(int err)
+{
+       if(err < 0 || err > ECONNREFUSED) {
+               err = ECONNREFUSED + 1;
+       }
+
+       return(_errno_str[err]);
+}