mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-15 00:54:22 +00:00

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>
24 lines
344 B
C
24 lines
344 B
C
/*
|
|
* 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;
|
|
}
|