[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [PATCH] lib/nolibc/string: import memrchr and strrchr from musl
tag: v1.1.20 commit <0fa1e638e87cf257e9f96b4019b2076afd674a19> Only style modifications have been applied on top of the original code Signed-off-by: Yuri Volchkov <yuri.volchkov@xxxxxxxxx> --- lib/nolibc/exportsyms.uk | 2 ++ lib/nolibc/include/string.h | 2 ++ lib/nolibc/string.c | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/lib/nolibc/exportsyms.uk b/lib/nolibc/exportsyms.uk index 61d49c72..702b1316 100644 --- a/lib/nolibc/exportsyms.uk +++ b/lib/nolibc/exportsyms.uk @@ -49,6 +49,7 @@ atoi memcpy memset memchr +memrchr memmove memcmp strnlen @@ -56,6 +57,7 @@ strlen strncpy strcpy strchr +strrchr strchrnul strncmp strcmp diff --git a/lib/nolibc/include/string.h b/lib/nolibc/include/string.h index b21e2c14..e9b52128 100644 --- a/lib/nolibc/include/string.h +++ b/lib/nolibc/include/string.h @@ -47,6 +47,7 @@ extern "C" { void *memcpy(void *dst, const void *src, size_t len); void *memset(void *ptr, int val, size_t len); void *memchr(const void *ptr, int val, size_t len); +void *memrchr(const void *m, int c, size_t n); int memcmp(const void *ptr1, const void *ptr2, size_t len); void *memmove(void *dst, const void *src, size_t len); @@ -56,6 +57,7 @@ size_t strnlen(const char *str, size_t maxlen); size_t strlen(const char *str); char *strchrnul(const char *s, int c); char *strchr(const char *str, int c); +char *strrchr(const char *s, int c); int strncmp(const char *str1, const char *str2, size_t len); int strcmp(const char *str1, const char *str2); size_t strcspn(const char *s, const char *c); diff --git a/lib/nolibc/string.c b/lib/nolibc/string.c index 6f853ba7..f67f2617 100644 --- a/lib/nolibc/string.c +++ b/lib/nolibc/string.c @@ -93,6 +93,17 @@ void *memchr(const void *ptr, int val, size_t len) return NULL; /* did not find val */ } +void *memrchr(const void *m, int c, size_t n) +{ + const unsigned char *s = m; + + c = (unsigned char) c; + while (n--) + if (s[n] == c) + return (void *) (s + n); + return 0; +} + void *memmove(void *dst, const void *src, size_t len) { uint8_t *d = dst; @@ -213,6 +224,11 @@ char *strchr(const char *str, int c) return *(unsigned char *)r == (unsigned char)c ? r : 0; } +char *strrchr(const char *s, int c) +{ + return memrchr(s, c, strlen(s) + 1); +} + size_t strcspn(const char *s, const char *c) { const char *a = s; -- 2.19.2 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |