From 6f7fe30ec66cb7bb062424c515679c1bad50f3dc Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 17 Dec 2016 19:12:57 +0000 Subject: [PATCH] [Minor] Add macro to assing rspamd_ftok_t from c string --- src/libutil/fstring.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libutil/fstring.h b/src/libutil/fstring.h index c1b2058178..ac69b01dfd 100644 --- a/src/libutil/fstring.h +++ b/src/libutil/fstring.h @@ -179,4 +179,15 @@ gchar *rspamd_ftokdup (const rspamd_ftok_t *src) G_GNUC_WARN_UNUSED_RESULT; gchar *rspamd_fstringdup (const rspamd_fstring_t *src) G_GNUC_WARN_UNUSED_RESULT; #define RSPAMD_FTOK_ASSIGN(t, lit) do { (t)->begin = (lit); (t)->len = sizeof(lit) - 1; } while (0) +#define RSPAMD_FTOK_FROM_STR(t, str) do { \ + if (G_LIKELY(str)) { \ + (t)->begin = (const char*)(str); \ + (t)->len = strlen (str); \ + } \ + else { \ + (t)->begin = NULL; \ + (t)->len = 0; \ + } \ +} while (0) + #endif -- 2.47.3