From 3ebceeece2204d3755df1f1cc8210f7e97b6daad Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 16 Nov 2010 22:00:29 +0300 Subject: Make own strlcpy that does not calculate remaining string length (faster and more safe) Allow only ASCII symbols in logs, escape control chars --- src/util.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/util.h') diff --git a/src/util.h b/src/util.h index f5ce840be..36d650877 100644 --- a/src/util.h +++ b/src/util.h @@ -108,6 +108,7 @@ void g_ptr_array_unref (GPtrArray *array); * %p void * * %V f_str_t * * %s null-terminated string + * %S ascii null-terminated string * %*s length and string * %Z '\0' * %N '\n' @@ -120,4 +121,26 @@ gint rspamd_fprintf (FILE *f, const gchar *fmt, ...); gint rspamd_snprintf (gchar *buf, size_t max, const gchar *fmt, ...); gchar *rspamd_vsnprintf (gchar *buf, size_t max, const gchar *fmt, va_list args); +/* + * Copy src to dest limited to len, in compare with standart strlcpy(3) rspamd strlcpy does not + * traverse the whole string and it is possible to use it for non NULL terminated strings. This is + * more like memccpy(dst, src, size, '\0') + * + * @param dst destination string + * @param src source string + * @param siz length of destination buffer + * @return bytes copied + */ +gsize rspamd_strlcpy (gchar *dst, const gchar *src, gsize siz); + +/* + * Escape rspamd string to write it to log file or other 7 bit prefferable places + * + * @param dst destination string + * @param src source string + * @param len length of destination buffer + * @return pointer to end of buffer + */ +gchar * rspamd_escape_string (gchar *dst, const gchar *src, gsize len); + #endif -- cgit v1.2.3