mruby-print/print.c: stop flushing every time in printstr

Instead, call `fflush` at the end of `print` method, if stdout is
connected to a tty.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-08-19 10:10:16 +09:00
parent 192e6e3b9f
commit 982a378425
+3 -1
View File
@@ -13,6 +13,8 @@
# define isatty(x) _isatty(x)
# define fileno(x) _fileno(x)
#endif
#else
# include <unistd.h>
#endif
static void
@@ -37,7 +39,6 @@ printstr(mrb_state *mrb, mrb_value s)
}
#endif
fwrite(p, (size_t)len, 1, stdout);
fflush(stdout);
}
}
@@ -53,6 +54,7 @@ mrb_print(mrb_state *mrb, mrb_value self)
mrb_value str = mrb_obj_as_string(mrb, argv[i]);
printstr(mrb, str);
}
if (isatty(fileno(stdout))) fflush(stdout);
return mrb_nil_value();
}