scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 5f464c4f5f082f5562a9ed1eb288366ef88147ea
parent 5ab34fe6b03c4e0938f17fe445e96bc19bf76768
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu, 19 May 2022 19:02:38 +0200

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.

Diffstat:
Msrc/libc/stdio/__putc.c | 6++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/libc/stdio/__putc.c b/src/libc/stdio/__putc.c @@ -24,10 +24,8 @@ __putc(int ch, FILE *fp) 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;