shithub: riscv

Download patch

ref: 61269254d0d5cc8e8e425cfb47774ec830dec2a3
parent: 7b36a7e1a9056bc8046d161c81aee008854daadf
author: mischief <mischief@offblast.org>
date: Wed Nov 6 06:22:15 EST 2013

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.

--- a/sys/src/ape/lib/ap/stdio/vfprintf.c
+++ b/sys/src/ape/lib/ap/stdio/vfprintf.c
@@ -202,7 +202,15 @@
 			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
--