diff options
-rw-r--r-- | src/libutil/str_util.c | 15 | ||||
-rw-r--r-- | src/libutil/str_util.h | 9 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c index f8441dcf1..4210adbe2 100644 --- a/src/libutil/str_util.c +++ b/src/libutil/str_util.c @@ -1881,3 +1881,18 @@ rspamd_urls_cmp (gconstpointer a, gconstpointer b) return r == 0; } + +const void * +rspamd_memrchr (const void *m, gint c, gsize len) +{ + const guint8 *p = m; + gsize i; + + for (i = len; i > 0; i --) { + if (p[i - 1] == c) { + return p + i - 1; + } + } + + return NULL; +} diff --git a/src/libutil/str_util.h b/src/libutil/str_util.h index 1ae09f576..91c80ff5d 100644 --- a/src/libutil/str_util.h +++ b/src/libutil/str_util.h @@ -310,4 +310,13 @@ gboolean rspamd_urls_cmp (gconstpointer a, gconstpointer b); extern const guchar lc_map[256]; +/** + * Search for the last occurrence of character `c` in memory block of size `len` + * @param m + * @param c + * @param len + * @return pointer to the last occurrence or NULL + */ +const void *rspamd_memrchr (const void *m, gint c, gsize len); + #endif /* SRC_LIBUTIL_STR_UTIL_H_ */ |