diff --git a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp index badeb0d65b1ff64eafb04b8388e5b798625d18f0..55668a336256b50e4e431c1b3e1995d93d32815d 100644 --- a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp @@ -330,8 +330,10 @@ napi_value PropNExporter::ReadSync(napi_env env, napi_callback_info info) NError(EINVAL).ThrowErr(env); return nullptr; } + if (!hasOffset) { + offset = -1; + } - ssize_t actLen; uv_buf_t buffer = uv_buf_init(static_cast(buf), len); std::unique_ptr read_req = { new uv_fs_t, CommonFunc::fs_req_cleanup }; @@ -346,8 +348,8 @@ napi_value PropNExporter::ReadSync(napi_env env, napi_callback_info info) NError(errno).ThrowErr(env); return nullptr; } - actLen = ret; - return NVal::CreateInt64(env, actLen).val_; + + return NVal::CreateInt64(env, ret).val_; } static NError ReadExec(shared_ptr arg, char *buf, size_t len, int fd, size_t offset) @@ -397,6 +399,9 @@ napi_value PropNExporter::Read(napi_env env, napi_callback_info info) NError(EINVAL).ThrowErr(env); return nullptr; } + if (!hasOffset) { + offset = -1; + } auto arg = make_shared(NVal(env, funcArg[NARG_POS::SECOND])); if (!arg) { @@ -481,6 +486,9 @@ napi_value PropNExporter::Write(napi_env env, napi_callback_info info) NError(EINVAL).ThrowErr(env); return nullptr; } + if (!hasOffset) { + offset = -1; + } auto arg = make_shared(move(bufGuard)); if (!arg) { @@ -548,8 +556,10 @@ napi_value PropNExporter::WriteSync(napi_env env, napi_callback_info info) HILOGE("Failed to resolve buf and options"); return nullptr; } + if (!hasOffset) { + offset = -1; + } - ssize_t writeLen; uv_buf_t buffer = uv_buf_init(static_cast(buf), len); std::unique_ptr write_req = { new uv_fs_t, CommonFunc::fs_req_cleanup }; @@ -564,8 +574,8 @@ napi_value PropNExporter::WriteSync(napi_env env, napi_callback_info info) NError(errno).ThrowErr(env); return nullptr; } - writeLen = ret; - return NVal::CreateInt64(env, writeLen).val_; + + return NVal::CreateInt64(env, ret).val_; } bool PropNExporter::Export()