From: Vsevolod Stakhov Date: Sat, 17 Dec 2016 19:12:57 +0000 (+0000) Subject: [Minor] Add macro to assing rspamd_ftok_t from c string X-Git-Tag: 1.5.0~565 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6f7fe30ec66cb7bb062424c515679c1bad50f3dc;p=thirdparty%2Frspamd.git [Minor] Add macro to assing rspamd_ftok_t from c string --- 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