]> mj.ucw.cz Git - libucw.git/blobdiff - lib/ff-printf.c
tried parametrized fastbuf for most of indexing I/O
[libucw.git] / lib / ff-printf.c
index d22d421d1d09a7f9be2632ff6573bb3fb43c1f65..8825a2880437dff93a19e29b5e947d68b294a64b 100644 (file)
@@ -1,7 +1,7 @@
 /*
- *     Sherlock Library -- Printf on Fastbuf Streams
+ *     UCW Library -- Printf on Fastbuf Streams
  *
- *     (c) 2002 Martin Mares <mj@ucw.cz>
+ *     (c) 2002--2005 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
 #include "lib/lib.h"
 #include "lib/fastbuf.h"
 
+#include <stdio.h>
 #include <alloca.h>
 
 int
-vbprintf(struct fastbuf *b, byte *msg, va_list args)
+vbprintf(struct fastbuf *b, char *msg, va_list args)
 {
   byte *buf;
   int len, r;
+  va_list args2;
 
   len = bdirect_write_prepare(b, &buf);
   if (len >= 16)
     {
-      r = vsnprintf(buf, len, msg, args);
+      va_copy(args2, args);
+      r = vsnprintf(buf, len, msg, args2);
+      va_end(args2);
       if (r < 0)
        len = 256;
       else if (r < len)
@@ -38,7 +42,9 @@ vbprintf(struct fastbuf *b, byte *msg, va_list args)
   while (1)
     {
       buf = alloca(len);
-      r = vsnprintf(buf, len, msg, args);
+      va_copy(args2, args);
+      r = vsnprintf(buf, len, msg, args2);
+      va_end(args2);
       if (r < 0)
        len += len;
       else if (r < len)
@@ -52,7 +58,7 @@ vbprintf(struct fastbuf *b, byte *msg, va_list args)
 }
 
 int
-bprintf(struct fastbuf *b, byte *msg, ...)
+bprintf(struct fastbuf *b, char *msg, ...)
 {
   va_list args;
   int res;