From d105b1d60a9a58c2d4c22e9ebecd2a9d0dea2750 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Sun, 23 May 2021 18:06:57 +0200 Subject: [PATCH] string: add stubs for strcoll and strxfrm (TEST) These extend the stub locale; strcoll is simply strcmp and strxfrm is simply strncpy. --- CMakeLists.txt | 4 +++- STATUS | 4 ++-- src/libc/string/strcoll.c | 8 ++++++++ src/libc/string/strxfrm.c | 8 ++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 src/libc/string/strcoll.c create mode 100644 src/libc/string/strxfrm.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 945fae2..585758f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,6 +139,7 @@ set(SOURCES src/libc/string/strchr.c src/libc/string/strchrnul.c src/libc/string/strcmp.c + src/libc/string/strcoll.c src/libc/string/strcpy.c src/libc/string/strcspn.c src/libc/string/strdup.c @@ -150,7 +151,8 @@ set(SOURCES src/libc/string/strndup.c src/libc/string/strnlen.c src/libc/string/strrchr.c - src/libc/string/strspn.c) + src/libc/string/strspn.c + src/libc/string/strxfrm.c) if(vhex-generic IN_LIST TARGET_FOLDERS) # TODO diff --git a/STATUS b/STATUS index dbbc4bd..6cb91f8 100644 --- a/STATUS +++ b/STATUS @@ -117,9 +117,9 @@ DONE: Function/symbol/macro is defined, builds, links, and is tested 7.21.3.2 strncat: DONE 7.21.4.1 memcmp: DONE 7.21.4.2 strcmp: DONE -! 7.21.4.3 strcoll: TODO +! 7.21.4.3 strcoll: TEST 7.21.4.4 strncmp: DONE -! 7.21.4.5 strxfrm: TODO +! 7.21.4.5 strxfrm: TEST 7.21.5.1 memchr: DONE 7.21.5.2 strchr: DONE 7.21.5.3 strcspn: DONE diff --git a/src/libc/string/strcoll.c b/src/libc/string/strcoll.c new file mode 100644 index 0000000..4e485b9 --- /dev/null +++ b/src/libc/string/strcoll.c @@ -0,0 +1,8 @@ +#include +#include + +/* Stub locale: use strcmp. */ +int strcoll(char const *s1, char const *s2) +{ + return strcmp(s1, s2); +} diff --git a/src/libc/string/strxfrm.c b/src/libc/string/strxfrm.c new file mode 100644 index 0000000..3f51805 --- /dev/null +++ b/src/libc/string/strxfrm.c @@ -0,0 +1,8 @@ +#include +#include + +size_t strxfrm(char * restrict dest, char const * restrict src, size_t n) +{ + if(dest) strncpy(dest, src, n); + return strlen(src); +}