summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-27 22:57:09 +0800
committerGitHub <[email protected]>2022-07-27 22:57:09 +0800
commitfcaff26e625dad6fe73a2a69a46346851afdd3fd (patch)
tree223912c77128acd5b9dea38fc2940410ff6aae55
parent43a82d1944819b465d06724abff535f3a4659de6 (diff)
parent35a16e3972d1f5993f47b1b4eaf61b27358176d6 (diff)
Merge pull request #2605 from xmake-io/stdio
set stdio buffer size
-rw-r--r--core/src/xmake/io/stdfile.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c
index 4838ebb0f..06d6fc579 100644
--- a/core/src/xmake/io/stdfile.c
+++ b/core/src/xmake/io/stdfile.c
@@ -33,7 +33,10 @@
# include <io.h>
# include "iscygpty.c"
#else
+# include <stdio.h>
# include <unistd.h>
+# include <sys/types.h>
+# include <sys/stat.h>
#endif
/* //////////////////////////////////////////////////////////////////////////////////////
@@ -78,6 +81,19 @@ static tb_size_t xm_io_stdfile_isatty(tb_size_t type)
if (answer) type |= XM_IO_FILE_FLAG_TTY;
return type;
}
+
+// @see https://github.com/xmake-io/xmake/issues/2580
+static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type)
+{
+#if !defined(TB_CONFIG_OS_WINDOWS)
+ struct stat stats;
+ tb_int_t size = BUFSIZ;
+ if (fstat(fileno(stdout), &stats) != -1)
+ size = stats.st_blksize;
+ setvbuf(stdout, tb_null, _IOLBF, size);
+#endif
+}
+
static xm_io_file_t* xm_io_stdfile_new(lua_State* lua, tb_size_t type)
{
// init stdfile
@@ -106,6 +122,9 @@ static xm_io_file_t* xm_io_stdfile_new(lua_State* lua, tb_size_t type)
file->type = xm_io_stdfile_isatty(type);
file->encoding = TB_CHARSET_TYPE_UTF8;
+ // init stdio buffer
+ xm_io_stdfile_init_buffer(type);
+
// init the read/write line cache buffer
tb_buffer_init(&file->rcache);
tb_buffer_init(&file->wcache);