aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libutil/printf.c31
-rw-r--r--src/libutil/printf.h4
2 files changed, 35 insertions, 0 deletions
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,