aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Prager <splinterofchaos@gmail.com>2014-09-27 21:00:19 -0400
committerThiago de Arruda <tpadilha84@gmail.com>2014-11-07 13:34:56 -0300
commit4df884a6113c8ce685dddb44628a936188532888 (patch)
tree1c63e03773f4beb88dee37adcc1364647d6a7947
parent07775c07c0c269fe70effa0489f65fb98143c12c (diff)
downloadrneovim-4df884a6113c8ce685dddb44628a936188532888.tar.gz
rneovim-4df884a6113c8ce685dddb44628a936188532888.tar.bz2
rneovim-4df884a6113c8ce685dddb44628a936188532888.zip
memory: implement xmemrchr()
-rw-r--r--src/nvim/memory.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/nvim/memory.c b/src/nvim/memory.c
index 59edefec4a..4b24213ecd 100644
--- a/src/nvim/memory.c
+++ b/src/nvim/memory.c
@@ -389,6 +389,25 @@ char *xstrdup(const char *str)
return ret;
}
+/// A version of memchr that starts the search at `src + len`.
+///
+/// Based on glibc's memrchr.
+///
+/// @param src The source memory object.
+/// @param c The byte to search for.
+/// @param len The length of the memory object.
+/// @returns a pointer to the found byte in src[len], or NULL.
+void *xmemrchr(void *src, uint8_t c, size_t len)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
+{
+ while (len--) {
+ if (((uint8_t *)src)[len] == c) {
+ return (uint8_t *) src + len;
+ }
+ }
+ return NULL;
+}
+
/// strndup() wrapper
///
/// @see {xmalloc}