shithub: scc

Download patch

ref: 5f464c4f5f082f5562a9ed1eb288366ef88147ea
parent: 5ab34fe6b03c4e0938f17fe445e96bc19bf76768
author: Hiltjo Posthuma <hiltjo@codemadness.org>
date: Thu May 19 15:02:38 EDT 2022

libc: don't set the error flag on string streams

This fixes the use-case:

	printf("%d\n", snprintf(NULL, 0, "abc"));

Printed -1, but should print 3.

--- a/src/libc/stdio/__putc.c
+++ b/src/libc/stdio/__putc.c
@@ -24,10 +24,8 @@
 		return EOF;
 	}
 
-	if (fp->flags & _IOSTRG) {
-		fp->flags |= _IOERR;
-		return EOF;
-	}
+	if (fp->flags & _IOSTRG)
+		return ch & 0xFF;
 
 	if (fp->buf == NULL && _allocbuf(fp))
 		return EOF;