mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-05-09 02:51:21 +00:00
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>
This commit is contained in:
parent
87b582ef5b
commit
ebff107268
3 changed files with 27 additions and 1 deletions
|
@ -12,6 +12,7 @@ LIBC_SRCS := $(addprefix lib/libc/, \
|
|||
memcmp.c \
|
||||
memcpy.c \
|
||||
memmove.c \
|
||||
memrchr.c \
|
||||
memset.c \
|
||||
printf.c \
|
||||
putchar.c \
|
||||
|
|
24
lib/libc/memrchr.c
Normal file
24
lib/libc/memrchr.c
Normal file
|
@ -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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue