From 61269254d0d5cc8e8e425cfb47774ec830dec2a3 Mon Sep 17 00:00:00 2001 From: mischief Date: Wed, 6 Nov 2013 11:22:15 -0800 Subject: [PATCH] synchronize ape's vfprintf with libstdio in ape's vfprintf we don't check if the file we're writing is actually a string buffer, resulting in a return of -1, when we should actually return the number of bytes that would be written. --- sys/src/ape/lib/ap/stdio/vfprintf.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sys/src/ape/lib/ap/stdio/vfprintf.c b/sys/src/ape/lib/ap/stdio/vfprintf.c index dc8c406ff..2df322421 100644 --- a/sys/src/ape/lib/ap/stdio/vfprintf.c +++ b/sys/src/ape/lib/ap/stdio/vfprintf.c @@ -202,7 +202,15 @@ vfprintf(FILE *f, const char *s, va_list args) nprint++; } } - return ferror(f)? -1: nprint;; + + if(ferror(f)){ + if((f->flags&STRING) && f->wp==f->rp && f->wp>f->buf){ + *(f->wp-1) = '\0'; + return nprint; + } + return -1; + } + return nprint; } static int