string: add memchr, memcmp, memmove for non-SuperH (TEST)

This commit is contained in:
Lephenixnoir 2021-05-23 16:45:02 +02:00
parent 5cfd2a7d85
commit fd0d67191c
Signed by untrusted user: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
4 changed files with 59 additions and 0 deletions

View File

@ -130,7 +130,10 @@ set(SOURCES
src/libc/stdlib/strtoul.c
src/libc/stdlib/strtoull.c
# string
src/libc/string/memchr.c
src/libc/string/memcmp.c
src/libc/string/memcpy.c
src/libc/string/memmove.c
src/libc/string/memset.c
src/libc/string/strcat.c
src/libc/string/strchr.c

16
src/libc/string/memchr.c Normal file
View File

@ -0,0 +1,16 @@
#include <string.h>
#ifndef __SUPPORT_ARCH_SH
void *memchr(void const *_s, int c, size_t n)
{
char const *s = _s;
for(size_t i = 0; i < n; i++) {
if(s[i] == c) return (char *)&s[i];
}
return NULL;
}
#endif /*__SUPPORT_ARCH_SH*/

18
src/libc/string/memcmp.c Normal file
View File

@ -0,0 +1,18 @@
#include <string.h>
#ifndef __SUPPORT_ARCH_SH
int memcmp(void const *_s1, void const *_s2, size_t n)
{
char const *s1 = _s1;
char const *s2 = _s2;
for(size_t i = 0; i < n; i++) {
int d = s1[i] - s2[i];
if(d != 0) return d;
}
return 0;
}
#endif /*__SUPPORT_ARCH_SH*/

22
src/libc/string/memmove.c Normal file
View File

@ -0,0 +1,22 @@
#include <string.h>
#ifndef __SUPPORT_ARCH_SH
void *memmove(void *_dest, void const *_src, size_t n)
{
char *dest = _dest;
char const *src = _src;
if(dest <= src) {
for(size_t i = 0; i < n; i++)
dest[i] = src[i];
}
else {
while(n-- > 0)
dest[n] = src[n];
}
return dest;
}
#endif /*__SUPPORT_ARCH_SH*/