From cfb37a5227c6599a3a7a5179c9c428bb07cde5ed Mon Sep 17 00:00:00 2001 From: Richard Nyberg Date: Fri, 21 Jul 2006 12:48:18 +0000 Subject: [PATCH] Split out common code for btpd_log and btpd_err. --- btpd/util.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/btpd/util.c b/btpd/util.c index f667c02..c4d4757 100644 --- a/btpd/util.c +++ b/btpd/util.c @@ -54,18 +54,24 @@ logtype_str(uint32_t type) return ""; } -void -btpd_err(const char *fmt, ...) +static void +log_common(uint32_t type, const char *fmt, va_list ap) { - va_list ap; - va_start(ap, fmt); - if (BTPD_L_ERROR & btpd_logmask) { + if (type & btpd_logmask) { char tbuf[20]; time_t tp = time(NULL); strftime(tbuf, 20, "%b %e %T", localtime(&tp)); - printf("%s %s: ", tbuf, logtype_str(BTPD_L_ERROR)); + printf("%s %s: ", tbuf, logtype_str(type)); vprintf(fmt, ap); } +} + +void +btpd_err(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + log_common(BTPD_L_ERROR, fmt, ap); va_end(ap); exit(1); } @@ -75,12 +81,6 @@ btpd_log(uint32_t type, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - if (type & btpd_logmask) { - char tbuf[20]; - time_t tp = time(NULL); - strftime(tbuf, 20, "%b %e %T", localtime(&tp)); - printf("%s %s: ", tbuf, logtype_str(type)); - vprintf(fmt, ap); - } + log_common(type, fmt, ap); va_end(ap); }