diff options
author | Ambroise Vincent <ambroise.vincent@arm.com> | 2019-06-19 17:14:09 +0100 |
---|---|---|
committer | Olivier Deprez <olivier.deprez@arm.com> | 2019-12-11 08:51:26 +0100 |
commit | ebff1072681c5ed09bb70d9c4f617476822db757 (patch) | |
tree | 0b1e03c3b589170de28561c3408a61b8b0e4a5ec /lib | |
parent | 87b582ef5b31c5893a470b61c217931fc7602da3 (diff) | |
download | platform_external_arm-trusted-firmware-ebff1072681c5ed09bb70d9c4f617476822db757.tar.gz platform_external_arm-trusted-firmware-ebff1072681c5ed09bb70d9c4f617476822db757.tar.bz2 platform_external_arm-trusted-firmware-ebff1072681c5ed09bb70d9c4f617476822db757.zip |
libc: add memrchr
This function scans a string backwards from the end for the first
instance of a character.
Change-Id: I46b21573ed25a0ff222eac340e1e1fb93b040763
Signed-off-by: Ambroise Vincent <ambroise.vincent@arm.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/libc.mk | 1 | ||||
-rw-r--r-- | lib/libc/memrchr.c | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/libc/libc.mk b/lib/libc/libc.mk index e1b5560f8..93d30d035 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 000000000..01caef3ae --- /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; +} |