diff options
| author | OpportunityLiu <[email protected]> | 2019-07-02 11:07:26 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-02 11:07:26 +0800 |
| commit | d4ca003b4b507c61429d8c48075a547d8309166d (patch) | |
| tree | 161e5aa62cc7cd3b7b58722ff6666fe5e38cfb15 | |
| parent | fc1f53d8282728b2877ae5ba96eff70e3cbc6bbf (diff) | |
fix file:flush()
| -rw-r--r-- | core/src/xmake/io/file_flush.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/core/src/xmake/io/file_flush.c b/core/src/xmake/io/file_flush.c index ac43f007d..5c0027d80 100644 --- a/core/src/xmake/io/file_flush.c +++ b/core/src/xmake/io/file_flush.c @@ -35,7 +35,21 @@ /* ////////////////////////////////////////////////////////////////////////////////////// * implementation */ -static tb_bool_t xm_io_std_flush(xm_io_file* file) { return !fflush(file->std_ref); } +static tb_bool_t xm_io_std_flush(xm_io_file* file) +{ + tb_assert_and_check_return_val(xm_io_file_is_std(file) && !xm_io_file_is_closed(file), tb_false); + return !fflush(file->std_ref); +} + +static tb_bool_t xm_io_file_flush(xm_io_file* file) +{ + tb_assert_and_check_return_val(xm_io_file_is_file(file) && !xm_io_file_is_closed(file), tb_false); + return tb_file_sync(file->file_ref); +} + +/* ////////////////////////////////////////////////////////////////////////////////////// + * interfaces + */ /* * file:flush() @@ -49,7 +63,7 @@ tb_int_t xm_io_file_flush(lua_State* lua) if (xm_io_file_is_closed(file)) xm_io_file_error_closed(lua); - tb_bool_t succeed = xm_io_file_is_file(file) ? tb_file_sync(file->file_ref) : xm_io_std_flush(file->std_ref); + tb_bool_t succeed = xm_io_file_is_file(file) ? xm_io_file_flush(file) : xm_io_std_flush(file); if (!succeed) xm_io_file_error(lua, "failed to flush file"); lua_pushboolean(lua, tb_true); |
