]> granicus.if.org Git - neomutt/commitdiff
debug: replace mutt_debug with a macro
authorRichard Russon <rich@flatcap.org>
Wed, 13 Sep 2017 15:26:41 +0000 (16:26 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 26 Nov 2017 22:52:51 +0000 (22:52 +0000)
The macro passes the file and line number to mutt_debug_real().

muttlib.c

index 447aff7c96b8231fb474587ffa6e0091d92e7574..fc95a4ab94dafbf309c36255b47007d8d49c116e 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -1866,25 +1866,29 @@ int debuglevel;
 char *debugfile_cmdline = NULL;
 int debuglevel_cmdline;
 
-void mutt_debug(int level, const char *fmt, ...)
+int mutt_debug_real(const char *function, const char *file, int line, int level, ...)
 {
   va_list ap;
   time_t now = time(NULL);
   static char buf[23] = "";
   static time_t last = 0;
+  int ret = 0;
 
-  if (debuglevel < level || !debugfile)
-    return;
+  if ((debuglevel < level) || !debugfile)
+    return 0;
 
   if (now > last)
   {
-    strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&now));
+    ret += strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", localtime(&now));
     last = now;
   }
-  fprintf(debugfile, "[%s] ", buf);
-  va_start(ap, fmt);
-  vfprintf(debugfile, fmt, ap);
+  ret += fprintf(debugfile, "[%s] %s() ", buf, function);
+
+  va_start(ap, level);
+  const char *fmt = va_arg(ap, const char *);
+  ret += vfprintf(debugfile, fmt, ap);
   va_end(ap);
+  return ret;
 }
 #endif