From 76424950e373d3b04ac3dd13019151bfba3e8423 Mon Sep 17 00:00:00 2001 From: sumuel Date: Mon, 17 Aug 2026 20:44:55 +0000 Subject: Add the files --- src/common/impl/memrchr.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/common/impl/memrchr.c (limited to 'src/common/impl/memrchr.c') diff --git a/src/common/impl/memrchr.c b/src/common/impl/memrchr.c new file mode 100644 index 0000000..aaf97e6 --- /dev/null +++ b/src/common/impl/memrchr.c @@ -0,0 +1,21 @@ +#include "common/memrchr.h" +#include +#include + +void* memrchr(const void* s, int c, size_t n) { + if (n == 0) { + return NULL; + } + + const uint8_t uc = (uint8_t) c; + + const uint8_t* p = (const uint8_t*) s + n; + + while (n--) { + if (*--p == uc) { + return (void*) p; + } + } + + return NULL; +} -- cgit v1.2.3