Browse Source

string: add and test strerror (DONE)

master
Lephenixnoir 8 months ago
parent
commit
b78cec4f6d
Signed by: Lephenixnoir GPG Key ID: 1BBA026E13FC0495
  1. 1
      CMakeLists.txt
  2. 2
      STATUS
  3. 15
      src/libc/string/strerror.c

1
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

2
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

15
src/libc/string/strerror.c

@ -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>";
}
Loading…
Cancel
Save