mirror of
https://git.planet-casio.com/Vhex-Kernel-Core/fxlibc.git
synced 2024-12-28 04:23:38 +01:00
string: add and test a naive memrchr (DONE)
This commit is contained in:
parent
909c7df815
commit
0c2f81e5bb
4 changed files with 17 additions and 0 deletions
|
@ -190,6 +190,7 @@ set(SOURCES
|
|||
src/libc/string/memcmp.c
|
||||
src/libc/string/memcpy.c
|
||||
src/libc/string/memmove.c
|
||||
src/libc/string/memrchr.c
|
||||
src/libc/string/memset.c
|
||||
src/libc/string/strcasecmp.c
|
||||
src/libc/string/strcasestr.c
|
||||
|
|
1
STATUS
1
STATUS
|
@ -200,6 +200,7 @@ TEST: Function/symbol/macro needs to be tested
|
|||
(EXT) strncasecmp -
|
||||
(EXT) strdup -
|
||||
(EXT) strndup -
|
||||
(EXT) memrchr -
|
||||
|
||||
7.22 <tgmath.h> => GCC
|
||||
|
||||
|
|
|
@ -54,6 +54,9 @@ extern size_t strxfrm(char * __restrict__ __dest,
|
|||
/* Search __c within the first __n characters of __s. */
|
||||
extern void *memchr(void const *__s, int __c, size_t __n);
|
||||
|
||||
/* Search the last occurrence of __c withing the first __n bytes of __s. */
|
||||
extern void *memrchr(void const *__s, int __c, size_t __n);
|
||||
|
||||
/* Find the first occurrence of __c within __s. */
|
||||
extern char *strchr(char const *__s, int __c);
|
||||
|
||||
|
|
12
src/libc/string/memrchr.c
Normal file
12
src/libc/string/memrchr.c
Normal file
|
@ -0,0 +1,12 @@
|
|||
#include <string.h>
|
||||
|
||||
void *memrchr(void const *_s, int c, size_t n)
|
||||
{
|
||||
char const *s = _s;
|
||||
|
||||
for(int i = n - 1; i >= 0; i--) {
|
||||
if(s[i] == c) return (char *)&s[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
Loading…
Reference in a new issue