From 074c15d4e08fb2f3e130eef8056de82b341f083e Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 6 Jul 2019 00:08:21 +0800 Subject: fix open file path --- core/src/xmake/io/file_read.c | 13 +++++++++---- core/src/xmake/io/open.c | 5 ++++- makefile | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c index 1bf722cc4..9cf183361 100644 --- a/core/src/xmake/io/file_read.c +++ b/core/src/xmake/io/file_read.c @@ -59,10 +59,15 @@ 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; while (!tb_stream_beof(stream)) { // read char - if (!tb_stream_bread_s8(stream, (tb_sint8_t*)&ch)) break; + if (!tb_stream_bread_s8(stream, (tb_sint8_t*)&ch)) + { + eof = tb_true; + break; + } // append char to line tb_buffer_memncat(line, (tb_byte_t const*)&ch, 1); @@ -75,7 +80,7 @@ static tb_long_t xm_io_file_buffer_readline(tb_stream_ref_t stream, tb_buffer_re // ok? tb_size_t size = tb_buffer_size(line); if (size) return size; - else return tb_stream_beof(stream)? -1 : 0; + else return (tb_stream_beof(stream) || eof)? -1 : 0; } static tb_int_t xm_io_file_buffer_pushline(luaL_Buffer* buf, xm_io_file* file, tb_char_t const* continuation, tb_bool_t keep_crlf) { @@ -196,9 +201,9 @@ static tb_int_t xm_io_file_read_all(lua_State* lua, xm_io_file* file, tb_char_t // check tb_assert(lua && file && continuation && xm_io_file_is_file(file) && !xm_io_file_is_closed(file)); - // is binary or no continuation? read all directly + // is binary? read all directly tb_bool_t is_binary = file->encoding == XM_IO_FILE_ENCODING_BINARY; - if (is_binary || *continuation == '\0') + if (is_binary) return xm_io_file_read_all_directly(lua, file); // read all diff --git a/core/src/xmake/io/open.c b/core/src/xmake/io/open.c index 0ee3d10cb..aa1512951 100644 --- a/core/src/xmake/io/open.c +++ b/core/src/xmake/io/open.c @@ -295,8 +295,11 @@ tb_int_t xm_io_open(lua_State* lua) // save file path tb_size_t pathlen = tb_strlen(path); xm_file->path = tb_malloc_cstr(pathlen + 1); - if (xm_file->path) + if (xm_file->path) + { tb_strncpy((tb_char_t*)xm_file->path, path, pathlen); + ((tb_char_t*)xm_file->path)[pathlen] = '\0'; + } // save file name tb_size_t name_maxn = tb_arrayn(xm_file->name); diff --git a/makefile b/makefile index a5c509c12..3646cc656 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,5 @@ # is debug? -debug :=y +debug :=n verbose:= #debug :=y -- cgit v1.3.1