aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2010-04-18 17:05:21 +0200
committerMatthias Andree <matthias.andree@gmx.de>2010-04-18 18:06:35 +0200
commit414a380974f78d0bb62ca953398bf1f54b28a58d (patch)
treeb7d4b9f851dfecb0978f4dc6f8e490b080afc9b2
parent254464339ec2b164905be726922649ad9672bd83 (diff)
downloadfetchmail-414a380974f78d0bb62ca953398bf1f54b28a58d.tar.gz
fetchmail-414a380974f78d0bb62ca953398bf1f54b28a58d.tar.bz2
fetchmail-414a380974f78d0bb62ca953398bf1f54b28a58d.zip
Factor out stdarg.h-based common code from report_build and _complete to _vbuild.
Note: varargs.h and non-*args.h stuff is untested.
-rw-r--r--report.c86
1 files changed, 35 insertions, 51 deletions
diff --git a/report.c b/report.c
index f8f2187f..5d9abb73 100644
--- a/report.c
+++ b/report.c
@@ -203,23 +203,11 @@ static void rep_ensuresize(void) {
}
}
-void
#ifdef HAVE_STDARG_H
-report_build (FILE *errfp, const char *message, ...)
-#else
-report_build (FILE *errfp, message, va_alist)
- const char *message;
- va_dcl
-#endif
+static void report_vbuild(const char *message, va_list args)
{
-#ifdef VA_START
- va_list args;
int n;
-#endif
-
- rep_ensuresize();
-#if defined(VA_START)
for ( ; ; )
{
/*
@@ -227,10 +215,11 @@ report_build (FILE *errfp, message, va_alist)
* because vsnprintf() invokes va_arg macro and thus args is
* undefined after the call.
*/
- VA_START(args, message);
n = vsnprintf (partial_message + partial_message_size_used, partial_message_size - partial_message_size_used,
message, args);
- va_end (args);
+
+ /* output error, f. i. EILSEQ */
+ if (n < 0) break;
if (n >= 0
&& (unsigned)n < partial_message_size - partial_message_size_used)
@@ -242,6 +231,30 @@ report_build (FILE *errfp, message, va_alist)
partial_message_size += 2048;
partial_message = (char *)REALLOC (partial_message, partial_message_size);
}
+}
+#endif
+
+void
+#ifdef HAVE_STDARG_H
+report_build (FILE *errfp, const char *message, ...)
+#else
+report_build (FILE *errfp, message, va_alist)
+ const char *message;
+ va_dcl
+#endif
+{
+#ifdef VA_START
+ va_list args;
+#else
+ int n;
+#endif
+
+ rep_ensuresize();
+
+#if defined(VA_START)
+ VA_START(args, message);
+ report_vbuild(message, args);
+ va_end(args);
#else
for ( ; ; )
{
@@ -249,6 +262,9 @@ report_build (FILE *errfp, message, va_alist)
partial_message_size - partial_message_size_used,
message, a1, a2, a3, a4, a5, a6, a7, a8);
+ /* output error, f. i. EILSEQ */
+ if (n < 0) break;
+
if (n >= 0
&& (unsigned)n < partial_message_size - partial_message_size_used)
{
@@ -294,48 +310,16 @@ report_complete (FILE *errfp, message, va_alist)
{
#ifdef VA_START
va_list args;
- int n;
#endif
rep_ensuresize();
#if defined(VA_START)
- for ( ; ; )
- {
- VA_START(args, message);
- n = vsnprintf (partial_message + partial_message_size_used,
- partial_message_size - partial_message_size_used,
- message, args);
- va_end(args);
-
- /* old glibc versions return -1 for truncation */
- if (n >= 0
- && (unsigned)n < partial_message_size - partial_message_size_used)
- {
- partial_message_size_used += n;
- break;
- }
-
- partial_message_size += 2048;
- partial_message = (char *)REALLOC (partial_message, partial_message_size);
- }
+ VA_START(args, message);
+ report_vbuild(message, args);
+ va_end(args);
#else
- for ( ; ; )
- {
- n = snprintf (partial_message + partial_message_size_used,
- partial_message_size - partial_message_size_used,
- message, a1, a2, a3, a4, a5, a6, a7, a8);
-
- if (n >= 0
- && (unsigned)n < partial_message_size - partial_message_size_used)
- {
- partial_message_size_used += n;
- break;
- }
-
- partial_message_size += 2048;
- partial_message = REALLOC (partial_message, partial_message_size);
- }
+ report_build(errfp, message, a1, a2, a3, a4, a5, a6, a7, a8);
#endif
/* Finally... print it. */