diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-23 12:23:52 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-08-23 12:23:52 +0100 |
commit | f0d7449414c8271fa4c232949ce9b57f32818562 (patch) | |
tree | 1b9c2e3950ef02c7615400105a806c34423268be | |
parent | 305de55ddaf9cd50e77dab247f433bf657f1c98d (diff) | |
download | rspamd-f0d7449414c8271fa4c232949ce9b57f32818562.tar.gz rspamd-f0d7449414c8271fa4c232949ce9b57f32818562.zip |
[Feature] Add rspamd_memrchr utility function
-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_ */ |