diff options
| author | ruki <[email protected]> | 2022-07-27 00:49:01 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2022-07-27 21:46:35 +0800 |
| commit | 3173f319e2aaeb9df6963c37f7209bed90762269 (patch) | |
| tree | a673def14f629b392a18448c51e8a2b325296395 | |
| parent | 43a82d1944819b465d06724abff535f3a4659de6 (diff) | |
set stdio buffer size
| -rw-r--r-- | core/src/xmake/io/stdfile.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/core/src/xmake/io/stdfile.c b/core/src/xmake/io/stdfile.c index 4838ebb0f..6f08c643c 100644 --- a/core/src/xmake/io/stdfile.c +++ b/core/src/xmake/io/stdfile.c @@ -78,6 +78,38 @@ static tb_size_t xm_io_stdfile_isatty(tb_size_t type) if (answer) type |= XM_IO_FILE_FLAG_TTY; return type; } + +static tb_void_t xm_io_stdfile_init_buffer(tb_size_t type) +{ +#if defined(TB_CONFIG_OS_WINDOWS) + // TODO +#else + tb_int_t size = 0; + tb_char_t data[256]; + switch (type) + { + case XM_IO_FILE_TYPE_STDIN: + { + if (tb_environment_first("XMAKE_STDIN_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) > 0)) + setvbuf(stdin, tb_null, _IONBF, 0); + } + break; + case XM_IO_FILE_TYPE_STDOUT: + { + if (tb_environment_first("XMAKE_STDOUT_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) > 0)) + setvbuf(stdout, tb_null, _IONBF, 0); + } + break; + case XM_IO_FILE_TYPE_STDERR: + { + if (tb_environment_first("XMAKE_STDERR_NBUF", data, sizeof(data)) && ((size = tb_stoi32(data)) > 0)) + setvbuf(stderr, tb_null, _IONBF, 0); + } + break; + } +#endif +} + static xm_io_file_t* xm_io_stdfile_new(lua_State* lua, tb_size_t type) { // init stdfile @@ -106,6 +138,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); |
