From 724fee890e1b2162987e3b779c17085b73bfb185 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Oct 2024 00:28:12 +0800 Subject: [PATCH] support r+b for io.open --- core/src/xmake/io/file_open.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/xmake/io/file_open.c b/core/src/xmake/io/file_open.c index ea5f36ddac5..3d9f164dc82 100644 --- a/core/src/xmake/io/file_open.c +++ b/core/src/xmake/io/file_open.c @@ -192,10 +192,14 @@ tb_int_t xm_io_file_open(lua_State* lua) case 'r': default: mode = TB_FILE_MODE_RO; break; } + // update file? + tb_bool_t update = !!tb_strchr(modestr, '+'); + if (update && mode == TB_FILE_MODE_RO) + mode = TB_FILE_MODE_RW; + // get file encoding tb_long_t bomoff = 0; tb_stream_ref_t stream = tb_null; - tb_bool_t update = !!tb_strchr(modestr, '+'); tb_size_t encoding = XM_IO_FILE_ENCODING_UNKNOWN; if (modestr[1] == 'b' || (update && modestr[2] == 'b')) encoding = XM_IO_FILE_ENCODING_BINARY;