From 4ef507e1592efbe33ca948f6bc76e4f100921184 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Mon, 9 May 2016 15:45:43 +0100 Subject: [Feature] Add utility method to convert ftok to C string --- src/libutil/fstring.c | 16 ++++++++++++++++ src/libutil/fstring.h | 8 ++++++++ 2 files changed, 24 insertions(+) (limited to 'src') diff --git a/src/libutil/fstring.c b/src/libutil/fstring.c index 997dd6b46..285940f9c 100644 --- a/src/libutil/fstring.c +++ b/src/libutil/fstring.c @@ -400,3 +400,19 @@ rspamd_ftok_cstr_equal (const rspamd_ftok_t *s, const gchar *pat, return (rspamd_ftok_cmp (s, &srch) == 0); } + +gchar * +rspamd_ftokdup (const rspamd_ftok_t *src) +{ + gchar *newstr; + + if (src == NULL) { + return NULL; + } + + newstr = g_malloc (src->len + 1); + memcpy (newstr, src->begin, src->len); + newstr[src->len] = '\0'; + + return newstr; +} diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h index 127557e40..10916d876 100644 --- a/src/libutil/fstring.h +++ b/src/libutil/fstring.h @@ -153,4 +153,12 @@ rspamd_ftok_t *rspamd_ftok_map (const rspamd_fstring_t *s); rspamd_fstring_t * rspamd_fstring_grow (rspamd_fstring_t *str, gsize needed_len) G_GNUC_WARN_UNUSED_RESULT; +/** + * Copies ftok to zero terminated string (must be freed using g_free) + * @param src + * @return + */ +gchar *rspamd_ftokdup (const rspamd_ftok_t *src) G_GNUC_WARN_UNUSED_RESULT; + + #endif -- cgit v1.2.3