From 9db64bdc897d378f2261567d9f2cfa8aeb8edd86 Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Thu, 9 Mar 2023 10:58:10 +0800 Subject: [PATCH] fixed 370b0a0 from https://gitee.com/zhuhongtao66/filemanagement_file_api/pulls/213 bugfix_fs_stream_write Signed-off-by: 18721213663 --- .../kits/js/src/mod_fs/class_stream/stream_n_exporter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/class_stream/stream_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/class_stream/stream_n_exporter.cpp index 7a79f7d49..4ed5f43e1 100644 --- a/interfaces/kits/js/src/mod_fs/class_stream/stream_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/class_stream/stream_n_exporter.cpp @@ -130,8 +130,8 @@ napi_value StreamNExporter::WriteSync(napi_env env, napi_callback_info cbInfo) } size_t writeLen = fwrite(buf, 1, len, filp); - if (writeLen != static_cast(len) && ferror(filp)) { - HILOGE("Failed to fwrite with len, writeLen: %{public}zu, len: %{public}" PRId64, writeLen, len); + if (writeLen == 0 && writeLen != len) { + HILOGE("Failed to fwrite stream"); NError(EIO).ThrowErr(env); return nullptr; } @@ -187,8 +187,8 @@ napi_value StreamNExporter::Write(napi_env env, napi_callback_info cbInfo) return NError(errno); } arg->actLen = fwrite(buf, 1, len, filp); - if ((arg->actLen != static_cast(len)) && ferror(filp)) { - HILOGE("Invalid buffer size and pointer, actlen: %{public}zu", arg->actLen); + if (arg->actLen == 0 && arg->actLen != len) { + HILOGE("Failed to fwrite stream"); return NError(EIO); } return NError(ERRNO_NOERR); -- Gitee