mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-26 06:50:10 +00:00
Merge "libc: add memrchr" into integration
This commit is contained in:
commit
fcccd358e4
3 changed files with 26 additions and 0 deletions
|
@ -19,6 +19,7 @@ int memcmp(const void *s1, const void *s2, size_t len);
|
||||||
int strcmp(const char *s1, const char *s2);
|
int strcmp(const char *s1, const char *s2);
|
||||||
int strncmp(const char *s1, const char *s2, size_t n);
|
int strncmp(const char *s1, const char *s2, size_t n);
|
||||||
void *memchr(const void *src, int c, size_t len);
|
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);
|
char *strchr(const char *s, int c);
|
||||||
void *memset(void *dst, int val, size_t count);
|
void *memset(void *dst, int val, size_t count);
|
||||||
size_t strlen(const char *s);
|
size_t strlen(const char *s);
|
||||||
|
|
|
@ -12,6 +12,7 @@ LIBC_SRCS := $(addprefix lib/libc/, \
|
||||||
memcmp.c \
|
memcmp.c \
|
||||||
memcpy.c \
|
memcpy.c \
|
||||||
memmove.c \
|
memmove.c \
|
||||||
|
memrchr.c \
|
||||||
memset.c \
|
memset.c \
|
||||||
printf.c \
|
printf.c \
|
||||||
putchar.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
Reference in a new issue