diff options
| author | ruki <[email protected]> | 2024-10-25 00:48:11 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-10-25 00:48:11 +0800 |
| commit | 179a663c2a2837b0d0a0784808a1591428d4c3a4 (patch) | |
| tree | 6bbfb4aad046d556a7e101c794bc38ad94fb82f8 | |
| parent | ecf4f21dd34c684e74618c95a4186d889badb5d3 (diff) | |
open stream
| -rw-r--r-- | core/src/xmake/utils/bin2c.c | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/core/src/xmake/utils/bin2c.c b/core/src/xmake/utils/bin2c.c index 921793345..ace4c51a4 100644 --- a/core/src/xmake/utils/bin2c.c +++ b/core/src/xmake/utils/bin2c.c @@ -62,5 +62,35 @@ tb_int_t xm_utils_bin2c(lua_State* lua) tb_trace_i("linewidth: %d", linewidth); tb_trace_i("nozeroend: %d", nozeroend); - return 0; + tb_bool_t ok = tb_false; + tb_stream_ref_t istream = tb_stream_init_from_file(binaryfile, TB_FILE_MODE_RO); + tb_stream_ref_t ostream = tb_stream_init_from_file(outputfile, TB_FILE_MODE_RW | TB_FILE_MODE_CREAT | TB_FILE_MODE_TRUNC); + do + { + if (!tb_stream_open(istream)) + { + lua_pushboolean(lua, tb_false); + lua_pushfstring(lua, "bin2c: open %s failed", binaryfile); + break; + } + + if (!tb_stream_open(ostream)) + { + lua_pushboolean(lua, tb_false); + lua_pushfstring(lua, "bin2c: open %s failed", outputfile); + break; + } + + ok = tb_true; + lua_pushboolean(lua, ok); + + } while (0); + + if (istream) tb_stream_clos(istream); + istream = tb_null; + + if (ostream) tb_stream_clos(ostream); + ostream = tb_null; + + return ok? 1 : 2; } |
