mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2025-04-19 17:37:09 +02:00
string: add memchr, memcmp, memmove for non-SuperH (TEST)
This commit is contained in:
parent
5cfd2a7d85
commit
fd0d67191c
4 changed files with 59 additions and 0 deletions
|
@ -130,7 +130,10 @@ set(SOURCES
|
||||||
src/libc/stdlib/strtoul.c
|
src/libc/stdlib/strtoul.c
|
||||||
src/libc/stdlib/strtoull.c
|
src/libc/stdlib/strtoull.c
|
||||||
# string
|
# string
|
||||||
|
src/libc/string/memchr.c
|
||||||
|
src/libc/string/memcmp.c
|
||||||
src/libc/string/memcpy.c
|
src/libc/string/memcpy.c
|
||||||
|
src/libc/string/memmove.c
|
||||||
src/libc/string/memset.c
|
src/libc/string/memset.c
|
||||||
src/libc/string/strcat.c
|
src/libc/string/strcat.c
|
||||||
src/libc/string/strchr.c
|
src/libc/string/strchr.c
|
||||||
|
|
16
src/libc/string/memchr.c
Normal file
16
src/libc/string/memchr.c
Normal 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
18
src/libc/string/memcmp.c
Normal 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
22
src/libc/string/memmove.c
Normal 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*/
|
Loading…
Add table
Reference in a new issue