ref: 628b7eaeb3daa2e2fa05171e399149bb3b804ad0
parent: cf234838bb0e7c772d6f3214a28fc55951737abe
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Sep 28 10:25:03 EDT 2018
[lib/c] Fix unbuffered output It needs a special case in __putc, because the character must be assigned before calling _flsbuf().
--- a/lib/c/__putc.c
+++ b/lib/c/__putc.c
@@ -60,10 +60,14 @@
*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:
--- a/lib/c/stdio.c
+++ b/lib/c/stdio.c
@@ -26,6 +26,8 @@
.fd = 2,
.buf = stderr->unbuf,
.len = sizeof(stderr->unbuf),
- .flags = _IOWRITE
+ .flags = _IOWRITE | _IONBF,
+ .rp = stderr->unbuf,
+ .wp = stderr->unbuf,
},
};