changeset 574:703bbeceb248 HEAD

Added printf_string_fix_format() which currently just replaces %m with strerror(errno). i_panic, i_fatal, i_error and i_warning didn't expand the %m before when not writing to syslog.
author Timo Sirainen <tss@iki.fi>
date Mon, 04 Nov 2002 07:33:48 +0200
parents c96607edbcb0
children ba6f89be8237
files src/lib/failures.c src/lib/strfuncs.c src/lib/strfuncs.h
diffstat 3 files changed, 14 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/failures.c	Mon Nov 04 07:23:47 2002 +0200
+++ b/src/lib/failures.c	Mon Nov 04 07:33:48 2002 +0200
@@ -64,7 +64,7 @@
 	write_prefix();
 
 	fputs("Panic: ", log_fd);
-	vfprintf(log_fd, format, args);
+	vfprintf(log_fd, printf_string_fix_format(format), args);
 	fputc('\n', log_fd);
 
 	abort();
@@ -75,7 +75,7 @@
 	write_prefix();
 
 	fputs("Fatal: ", log_fd);
-	vfprintf(log_fd, format, args);
+	vfprintf(log_fd, printf_string_fix_format(format), args);
 	fputc('\n', log_fd);
 
 	exit(98);
@@ -87,9 +87,11 @@
 
 	write_prefix();
 
+	t_push();
 	fputs("Error: ", log_fd);
-	vfprintf(log_fd, format, args);
+	vfprintf(log_fd, printf_string_fix_format(format), args);
         fputc('\n', log_fd);
+	t_pop();
 
 	fflush(log_fd);
 
@@ -102,9 +104,11 @@
 
 	write_prefix();
 
+	t_push();
 	fputs("Warning: ", log_fd);
-	vfprintf(log_fd, format, args);
-        fputc('\n', log_fd);
+	vfprintf(log_fd, printf_string_fix_format(format), args);
+	fputc('\n', log_fd);
+	t_pop();
 
 	fflush(log_fd);
 
--- a/src/lib/strfuncs.c	Mon Nov 04 07:23:47 2002 +0200
+++ b/src/lib/strfuncs.c	Mon Nov 04 07:33:48 2002 +0200
@@ -373,7 +373,7 @@
 }
 
 /* replace %m with strerror() */
-static const char *fix_format(const char *fmt)
+const char *printf_string_fix_format(const char *fmt)
 {
 	const char *p;
 
@@ -397,7 +397,7 @@
 
 	t_push();
 	va_start(args, format);
-	ret = vsnprintf(str, max_chars, fix_format(format), args);
+	ret = vsnprintf(str, max_chars, printf_string_fix_format(format), args);
 	va_end(args);
 	t_pop();
 
@@ -419,7 +419,7 @@
 	t_push();
 
 	va_start(args, format);
-	format = fix_format(format);
+	format = printf_string_fix_format(format);
 	buf = t_buffer_get(printf_string_upper_bound(format, args));
 	va_end(args);
 
@@ -601,7 +601,7 @@
 	if (format == NULL)
 		return NULL;
 
-	format = fix_format(format);
+	format = printf_string_fix_format(format);
 
 	VA_COPY(temp_args, args);
 
--- a/src/lib/strfuncs.h	Mon Nov 04 07:23:47 2002 +0200
+++ b/src/lib/strfuncs.h	Mon Nov 04 07:33:48 2002 +0200
@@ -5,6 +5,7 @@
         ((str) == NULL || (str)[0] == '\0')
 
 size_t printf_string_upper_bound(const char *format, va_list args);
+const char *printf_string_fix_format(const char *fmt);
 int i_snprintf(char *str, size_t max_chars, const char *format, ...)
 	__attr_format__(3, 4);