diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-10-27 15:50:36 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2015-10-27 15:52:09 +0200 |
commit | 9ae85910bc0e2d022e560dd08bcc71b956553c5d (patch) | |
tree | 65055a4d44a9a9bb98131351b89f75f0f1759d05 /libmailutils/diag/debug.c | |
parent | 0bd9e1759058e0d7b1e3e4be205a65e1e1bedab2 (diff) | |
download | mailutils-9ae85910bc0e2d022e560dd08bcc71b956553c5d.tar.gz mailutils-9ae85910bc0e2d022e560dd08bcc71b956553c5d.tar.bz2 |
Improve debugging
* libmailutils/diag/debug.c (mu_debug_log): Account for
eventual newlines in the generated message string.
* imap4d/io.c (imap4d_init_tls_server): Use mu_stream_strerror.
Diffstat (limited to 'libmailutils/diag/debug.c')
-rw-r--r-- | libmailutils/diag/debug.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/libmailutils/diag/debug.c b/libmailutils/diag/debug.c index 3ad00b2a2..e5def63bb 100644 --- a/libmailutils/diag/debug.c +++ b/libmailutils/diag/debug.c @@ -34,6 +34,7 @@ #include <mailutils/stdstream.h> #include <mailutils/iterator.h> #include <mailutils/cstr.h> +#include <mailutils/io.h> int mu_debug_line_info; /* Debug messages include source locations */ @@ -675,13 +676,30 @@ void mu_debug_log (const char *fmt, ...) { va_list ap; + char *buf = NULL; + size_t buflen = 0; + size_t n; + int rc; mu_diag_init (); va_start (ap, fmt); - mu_stream_printf (mu_strerr, "\033s<%d>", MU_LOG_DEBUG); - mu_stream_vprintf (mu_strerr, fmt, ap); - mu_stream_write (mu_strerr, "\n", 1, NULL); + rc = mu_vasnprintf (&buf, &buflen, fmt, ap); va_end (ap); + if (rc == 0) + { + size_t i; + int nl = 0; + for (i = 0; buf[i]; i += n) + { + n = strcspn (buf + i, "\n"); + if ((nl = buf[i + n])) + ++n; + mu_stream_printf (mu_strerr, "\033s<%d>", MU_LOG_DEBUG); + mu_stream_write (mu_strerr, buf + i, n, NULL); + } + if (!nl) + mu_stream_write (mu_strerr, "\n", 1, NULL); + } } void |