summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2019-07-06 11:21:16 +0800
committerruki <[email protected]>2019-07-06 11:21:16 +0800
commit6d7a7e8fef7ca7d1129883e02c6dad2314b47259 (patch)
treee6d1ffc53509640f1fe3360d98b519b3735eb860 /core/src
parentd6dd8b3570ba883f2e1e630c7fb16023d6a47a3a (diff)
improve to read all
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/io/file_read.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c
index 959b820ec..6d16748ff 100644
--- a/core/src/xmake/io/file_read.c
+++ b/core/src/xmake/io/file_read.c
@@ -54,27 +54,31 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re
// read line and reserve crlf
tb_char_t ch = 0;
tb_bool_t eof = tb_false;
+ tb_size_t need = 512;
tb_byte_t* p = tb_null;
while (!tb_stream_beof(stream))
{
- if (tb_stream_need(stream, &p, TB_STREAM_BLOCK_MAXN) && p)
+ if (need && tb_stream_need(stream, &p, need) && p)
{
- tb_char_t const* e = tb_strnchr((tb_char_t const*)p, TB_STREAM_BLOCK_MAXN, '\n');
+ tb_char_t const* e = tb_strnchr((tb_char_t const*)p, need, '\n');
if (e)
{
tb_size_t n = (tb_byte_t const*)e + 1 - p;
if (!tb_stream_skip(stream, n)) return -1;
tb_buffer_memncat(line, p, n);
- return tb_buffer_size(line);
+ break;
}
else
{
- if (!tb_stream_skip(stream, TB_STREAM_BLOCK_MAXN)) return -1;
- tb_buffer_memncat(line, p, TB_STREAM_BLOCK_MAXN);
+ if (!tb_stream_skip(stream, need)) return -1;
+ tb_buffer_memncat(line, p, need);
}
}
else
{
+ // disable need operation
+ need = 0;
+
// read char
if (!tb_stream_bread_s8(stream, (tb_sint8_t*)&ch))
{
@@ -86,8 +90,7 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re
tb_buffer_memncat(line, (tb_byte_t const*)&ch, 1);
// is line?
- if (ch == '\n')
- return tb_buffer_size(line);
+ if (ch == '\n') break;
}
}