aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexei Fedorov <Alexei.Fedorov@arm.com>2019-12-11 10:14:13 +0000
committerTrustedFirmware Code Review <review@review.trustedfirmware.org>2019-12-11 10:14:13 +0000
commitfcccd358e4cd6199c797ad127c77c47ec1ad5983 (patch)
tree4806d68c350001c4980429f78a907e137e92642f
parent2bcaeab6639396c7b54db62a0fbb07798ab83a57 (diff)
parentebff1072681c5ed09bb70d9c4f617476822db757 (diff)
downloadtrusted-firmware-a-fcccd358e4cd6199c797ad127c77c47ec1ad5983.tar.gz
Merge "libc: add memrchr" into integration
-rw-r--r--include/lib/libc/string.h1
-rw-r--r--lib/libc/libc.mk1
-rw-r--r--lib/libc/memrchr.c24
3 files changed, 26 insertions, 0 deletions
diff --git a/include/lib/libc/string.h b/include/lib/libc/string.h
index c92b6808c4..71774b0c81 100644
--- a/include/lib/libc/string.h
+++ b/include/lib/libc/string.h
@@ -19,6 +19,7 @@ int memcmp(const void *s1, const void *s2, size_t len);
int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
void *memchr(const void *src, int c, size_t len);
+void *memrchr(const void *src, int c, size_t len);
char *strchr(const char *s, int c);
void *memset(void *dst, int val, size_t count);
size_t strlen(const char *s);
diff --git a/lib/libc/libc.mk b/lib/libc/libc.mk
index e1b5560f84..93d30d0356 100644
--- a/lib/libc/libc.mk
+++ b/lib/libc/libc.mk
@@ -12,6 +12,7 @@ LIBC_SRCS := $(addprefix lib/libc/, \
memcmp.c \
memcpy.c \
memmove.c \
+ memrchr.c \
memset.c \
printf.c \
putchar.c \
diff --git a/lib/libc/memrchr.c b/lib/libc/memrchr.c
new file mode 100644
index 0000000000..01caef3aef
--- /dev/null
+++ b/lib/libc/memrchr.c
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <string.h>
+
+#undef memrchr
+
+void *memrchr(const void *src, int c, size_t len)
+{
+ const unsigned char *s = src + (len - 1);
+
+ while (len--) {
+ if (*s == (unsigned char)c) {
+ return (void*) s;
+ }
+
+ s--;
+ }
+
+ return NULL;
+}