From f6240cced088030abb377c5e10bcbd0943e3f2b2 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 6 Oct 2015 17:11:56 +0100 Subject: [PATCH] Add printing to rspamd_fstring_t. --- src/libutil/printf.c | 31 +++++++++++++++++++++++++++++++ src/libutil/printf.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/src/libutil/printf.c b/src/libutil/printf.c index 9204060b2..345682f28 100644 --- a/src/libutil/printf.c +++ b/src/libutil/printf.c @@ -219,6 +219,18 @@ rspamd_printf_append_gstring (const gchar *buf, glong buflen, gpointer ud) return buflen; } +static glong +rspamd_printf_append_fstring (const gchar *buf, glong buflen, gpointer ud) +{ + rspamd_fstring_t **dst = ud; + + if (buflen > 0) { + *dst = rspamd_fstring_append (*dst, buf, buflen); + } + + return buflen; +} + glong rspamd_fprintf (FILE *f, const gchar *fmt, ...) { @@ -307,6 +319,25 @@ rspamd_vprintf_gstring (GString *s, const gchar *fmt, va_list args) return rspamd_vprintf_common (rspamd_printf_append_gstring, s, fmt, args); } +glong +rspamd_printf_fstring (rspamd_fstring_t **s, const gchar *fmt, ...) +{ + va_list args; + glong r; + + va_start (args, fmt); + r = rspamd_vprintf_fstring (s, fmt, args); + va_end (args); + + return r; +} + +glong +rspamd_vprintf_fstring (rspamd_fstring_t **s, const gchar *fmt, va_list args) +{ + return rspamd_vprintf_common (rspamd_printf_append_fstring, s, fmt, args); +} + #define RSPAMD_PRINTF_APPEND(buf, len) \ do { \ RSPAMD_PRINTF_APPEND_BUF(buf, len); \ diff --git a/src/libutil/printf.h b/src/libutil/printf.h index 8cd699212..ea73cf0a0 100644 --- a/src/libutil/printf.h +++ b/src/libutil/printf.h @@ -26,6 +26,7 @@ #define PRINTF_H_ #include "config.h" +#include "fstring.h" /* * supported formats: @@ -78,6 +79,9 @@ gchar * rspamd_vsnprintf (gchar *buf, glong max, const gchar *fmt, glong rspamd_printf_gstring (GString *s, const gchar *fmt, ...); glong rspamd_vprintf_gstring (GString *s, const gchar *fmt, va_list args); +glong rspamd_printf_fstring (rspamd_fstring_t **s, const gchar *fmt, ...); +glong rspamd_vprintf_fstring (rspamd_fstring_t **s, const gchar *fmt, va_list args); + glong rspamd_vprintf_common (rspamd_printf_append_func func, gpointer apd, const gchar *fmt, -- 2.39.5