scc

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

commit 6e5e998efb6bbb9f65cff011c2f99162bd883ff1
parent 63f255f9a07e605d18170a869f2808e669c10706
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 28 Sep 2018 14:25:03 +0100

[lib/c] Fix unbuffered output

It needs a special case in __putc, because the character
must be assigned before calling _flsbuf().

Diffstat:
Mlib/c/__putc.c | 6+++++-
Mlib/c/stdio.c | 4+++-
2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/c/__putc.c b/lib/c/__putc.c @@ -60,10 +60,14 @@ __putc(int ch, FILE *fp) *fp->lp++ = ch; if (ch == '\n' && _flsbuf(fp)) return EOF; - } else { + } else if (fp->flags & _IOFBF) { if (fp->wp == fp->rp && _flsbuf(fp)) return EOF; *fp->wp++ = ch; + } else { + *fp->wp++ = ch; + if (_flsbuf(fp)) + return EOF; } done: diff --git a/lib/c/stdio.c b/lib/c/stdio.c @@ -26,6 +26,8 @@ FILE __iob[FOPEN_MAX] = { .fd = 2, .buf = stderr->unbuf, .len = sizeof(stderr->unbuf), - .flags = _IOWRITE + .flags = _IOWRITE | _IONBF, + .rp = stderr->unbuf, + .wp = stderr->unbuf, }, };