Browse Source

[Feature] Add rspamd_memrchr utility function

tags/1.3.4
Vsevolod Stakhov 7 years ago
parent
commit
f0d7449414
2 changed files with 24 additions and 0 deletions
  1. 15
    0
      src/libutil/str_util.c
  2. 9
    0
      src/libutil/str_util.h

+ 15
- 0
src/libutil/str_util.c View File

@@ -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;
}

+ 9
- 0
src/libutil/str_util.h View File

@@ -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_ */

Loading…
Cancel
Save