summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2006-07-21 12:48:18 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2006-07-21 12:48:18 +0000
commitcfb37a5227c6599a3a7a5179c9c428bb07cde5ed (patch)
treec5ccd5b52fc9720aa816123b3ac732b6e84dc5b7
parented56df9e56228b22b4b99ab3a52059d9fbef8e43 (diff)
downloadbtpd-cfb37a5227c6599a3a7a5179c9c428bb07cde5ed.tar.gz
btpd-cfb37a5227c6599a3a7a5179c9c428bb07cde5ed.zip
Split out common code for btpd_log and btpd_err.
-rw-r--r--btpd/util.c26
1 files 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);
 }