string: add and test strerror (DONE)

This commit is contained in:
Lephenixnoir 2021-05-23 17:44:37 +02:00
parent 2a78c17597
commit b78cec4f6d
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
3 changed files with 17 additions and 1 deletions

View file

@ -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

2
STATUS
View file

@ -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

View file

@ -0,0 +1,15 @@
#include <string.h>
#include <errno.h>
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] : "<Unknown errno>";
}