From e0fa180c4b80a2cdd834c823306e9beb438f39ad Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Sat, 15 Aug 2020 15:15:40 +0900 Subject: [PATCH] libc: Add strerror() implementation --- include/string.h | 1 + libc/string.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/string.h b/include/string.h index 9697603..536b54b 100644 --- a/include/string.h +++ b/include/string.h @@ -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 */ diff --git a/libc/string.c b/libc/string.c index a8e548a..566a222 100644 --- a/libc/string.c +++ b/libc/string.c @@ -1,4 +1,5 @@ #include +#include 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]); +} -- 2.47.3