diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ffd8e2..cb2fc6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,6 +141,7 @@ set(SOURCES src/libc/string/strcmp.c src/libc/string/strcpy.c src/libc/string/strdup.c + src/libc/string/strerror.c src/libc/string/strlen.c src/libc/string/strncat.c src/libc/string/strncmp.c diff --git a/STATUS b/STATUS index 7fb0a2c..92d272c 100644 --- a/STATUS +++ b/STATUS @@ -129,7 +129,7 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested ! 7.21.5.7 strstr: TODO ! 7.21.5.8 strtok: TODO 7.21.6.1 memset: DONE -! 7.21.6.2 strerror: TODO + 7.21.6.2 strerror: DONE 7.21.6.3 strlen: DONE Extensions: ! - strnlen: TODO diff --git a/src/libc/string/strerror.c b/src/libc/string/strerror.c new file mode 100644 index 0000000..0a91180 --- /dev/null +++ b/src/libc/string/strerror.c @@ -0,0 +1,15 @@ +#include +#include + +static char *errno_strings [] = { + [0] = "Success", + [EDOM] = "Numerical argument out of domain", + [EILSEQ] = "Invalid or incomplete multibyte or wide character", + [ERANGE] = "Numerical result out of range", +}; + +char *strerror(int e) +{ + int count = sizeof errno_strings / sizeof errno_strings[0]; + return (e >= 0 && e < count) ? errno_strings[e] : ""; +}