Skip to content

Commit c0ec408

Browse files
committed
Fixed stdout not being line-buffered.
1 parent 427700d commit c0ec408

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

runtime/sys.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ namespace sys {
354354
void write_string(stream& io, const char* str, u32 n) {
355355
u32 i = 0;
356356
if (&io == &io_for_fd(BASIL_STDOUT_FD)) for (i = 0; i < n; i ++) {
357-
push_if_necessary(io, 4);
357+
push_if_necessary(io, 1);
358358
io.buf[io.end ++] = str[i];
359359
if (str[i] == '\n') flush_output(io);
360360
}
@@ -371,11 +371,13 @@ namespace sys {
371371
void write_char(stream& io, rune c) {
372372
push_if_necessary(io, 4);
373373
io.end += utf8_encode(&c, 1, io.buf + io.end, 4);
374+
if (&io == &io_for_fd(BASIL_STDOUT_FD) && c == '\n') flush_output(io);
374375
}
375376

376377
void write_byte(stream& io, u8 c) {
377378
push_if_necessary(io, 1);
378379
put(io, c);
380+
if (&io == &io_for_fd(BASIL_STDOUT_FD) && c == '\n') flush_output(io);
379381
}
380382

381383
bool isdigit(char c) {

0 commit comments

Comments
 (0)