mirror of
https://github.com/openharmony/commonlibrary_utils_lite.git
synced 2026-07-19 11:34:40 -04:00
!112 Decouple the ohos code of drivers based on the Pegasus architecture
Merge pull request !112 from zk/master
This commit is contained in:
+9
-1
@@ -19,7 +19,15 @@ 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" ]
|
||||
}
|
||||
deps += [ "//commonlibrary/utils_lite/hals/file:static_hal_file" ]
|
||||
}
|
||||
|
||||
lite_component("file") {
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
}
|
||||
@@ -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 <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user