From bb9942590974c3e6b9f69a96920458af3ea1936c Mon Sep 17 00:00:00 2001 From: zk Date: Tue, 3 Jan 2023 19:04:05 +0800 Subject: [PATCH] Synchronize 'Resolve the dependency order error' issue to monthly1018 branch Synchronize 'Resolve the dependency order error' issue to monthly1018 branch Issue: I6812R Test: NA Signed-off-by: zk --- file/BUILD.gn | 11 +++++++- hals/file/BUILD.gn | 23 +++++++++++++++++ hals/file/hal_file.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 hals/file/BUILD.gn create mode 100644 hals/file/hal_file.c diff --git a/file/BUILD.gn b/file/BUILD.gn index 07e2b07..6071f96 100644 --- a/file/BUILD.gn +++ b/file/BUILD.gn @@ -19,7 +19,16 @@ static_library("native_file") { "//commonlibrary/utils_lite/include", "//commonlibrary/utils_lite/hals/file", ] - deps = [ "$ohos_board_adapter_dir/hals/utils/file:hal_file_static" ] + BOARD_DRIVER_HAL_FILE_PATH = + rebase_path("${ohos_board_adapter_dir}/hals/utils/file") + cmd = "if [ -f ${BOARD_DRIVER_HAL_FILE_PATH}/BUILD.gn ]; then echo true; else echo false; fi" + BOARD_DRIVER_HAL_FILE_PATH_EXISTS = + exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + if (BOARD_DRIVER_HAL_FILE_PATH_EXISTS) { + deps = [ "$ohos_board_adapter_dir/hals/utils/file:hal_file_static" ] + } else { + deps = [ "//commonlibrary/utils_lite/hals/file:static_hal_file" ] + } } lite_component("file") { diff --git a/hals/file/BUILD.gn b/hals/file/BUILD.gn new file mode 100644 index 0000000..7cc5249 --- /dev/null +++ b/hals/file/BUILD.gn @@ -0,0 +1,23 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") + +ohos_static_library("static_hal_file") { + sources = [ "hal_file.c" ] + + include_dirs = [ + "//commonlibrary/utils_lite/include", + "//commonlibrary/utils_lite/hals/file", + ] +} diff --git a/hals/file/hal_file.c b/hals/file/hal_file.c new file mode 100644 index 0000000..9d21f08 --- /dev/null +++ b/hals/file/hal_file.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include + +#include "hal_file.h" + +int HalFileOpen(const char *path, int oflag, int mode) +{ + (void)mode; + return open(path, oflag); +} + +int HalFileClose(int fd) +{ + return close(fd); +} + +int HalFileRead(int fd, char *buf, unsigned int len) +{ + return read(fd, buf, len); +} + +int HalFileWrite(int fd, const char *buf, unsigned int len) +{ + return write(fd, buf, len); +} + +int HalFileDelete(const char *path) +{ + return unlink(path); +} + +int HalFileStat(const char *path, unsigned int *fileSize) +{ + struct stat info = { 0 }; + int ret = stat(path, &info); + if (ret < 0) { + return ret; + } else { + return info.st_size; + } +} + +int HalFileSeek(int fd, int offset, unsigned int whence) +{ + return lseek(fd, offset, whence); +} \ No newline at end of file -- Gitee