From 5fe9999527c726cdf1f320e58b3afddd7ffe358f Mon Sep 17 00:00:00 2001 From: tianp Date: Mon, 4 Aug 2025 17:23:11 +0800 Subject: [PATCH] =?UTF-8?q?createrandomaccess=E6=8E=A5=E5=8F=A3=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=89=93=E5=8D=B0=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tianp Change-Id: Ic5f4af5d442bfa2431048fbeaa78c2b79a47d709 --- .../src/mod_fs/properties/create_randomaccessfile_core.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/create_randomaccessfile_core.cpp b/interfaces/kits/js/src/mod_fs/properties/create_randomaccessfile_core.cpp index d7d99779d..fd2b0f1a6 100644 --- a/interfaces/kits/js/src/mod_fs/properties/create_randomaccessfile_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/create_randomaccessfile_core.cpp @@ -12,6 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include "create_randomaccessfile_core.h" #include @@ -37,6 +38,7 @@ static tuple ParseStringToFileInfo(const string &path) close(sfd); return { false, FileInfo { false, nullptr, nullptr }, ENOMEM}; } + size_t length = path.length() + 1; auto chars = std::make_unique(length); auto ret = strncpy_s(chars.get(), length, path.c_str(), length - 1); @@ -53,11 +55,13 @@ static tuple ParseFdToFileInfo(const int32_t &fd) HILOGE("Invalid fd"); return { false, FileInfo { false, nullptr, nullptr }, EINVAL}; } + auto dupFd = dup(fd); if (dupFd < 0) { HILOGE("Failed to get valid fd, fail reason: %{public}s, fd: %{public}d", strerror(errno), fd); return { false, FileInfo { false, nullptr, nullptr }, EINVAL}; } + auto fdg = CreateUniquePtr(dupFd, false); if (fdg == nullptr) { HILOGE("Failed to request heap memory."); @@ -114,7 +118,7 @@ static tuple ValidAndConvertFlags(const option if (options.has_value()) { auto [succOpt, start, end] = ValidRafOptions(options); if (!succOpt) { - HILOGE("invalid RandomAccessFile options"); + HILOGE("Invalid RandomAccessFile options"); return {false, flags, start, end}; } } -- Gitee