diff --git a/file/BUILD.gn b/file/BUILD.gn index 07e2b07b6cac3342e66bc0633026d6450eb19961..f1b30e3606bada32293841b4707ce7dcc9250b8f 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" ] + deps = [] + 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" ] + } + 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 0000000000000000000000000000000000000000..7cc5249758965b0bd8a58d3abfa646b53278914b --- /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 0000000000000000000000000000000000000000..84fb576229b231434d71fd4d712f8478a31d6cd2 --- /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" + +__attribute__((weak)) int HalFileOpen(const char *path, int oflag, int mode) +{ + (void)mode; + return open(path, oflag); +} + +__attribute__((weak)) int HalFileClose(int fd) +{ + return close(fd); +} + +__attribute__((weak)) int HalFileRead(int fd, char *buf, unsigned int len) +{ + return read(fd, buf, len); +} + +__attribute__((weak)) int HalFileWrite(int fd, const char *buf, unsigned int len) +{ + return write(fd, buf, len); +} + +__attribute__((weak)) int HalFileDelete(const char *path) +{ + return unlink(path); +} + +__attribute__((weak)) 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; + } +} + +__attribute__((weak)) int HalFileSeek(int fd, int offset, unsigned int whence) +{ + return lseek(fd, offset, whence); +} \ No newline at end of file