1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15#include <fcntl.h> 16#include <unistd.h> 17#include <sys/stat.h> 18 19#include "hal_file.h" 20 21int HalFileOpen(const char *path, int oflag, int mode) 22{ 23 (void)mode; 24 return open(path, oflag); 25} 26 27int HalFileClose(int fd) 28{ 29 return close(fd); 30} 31 32int HalFileRead(int fd, char *buf, unsigned int len) 33{ 34 return read(fd, buf, len); 35} 36 37int HalFileWrite(int fd, const char *buf, unsigned int len) 38{ 39 return write(fd, buf, len); 40} 41 42int HalFileDelete(const char *path) 43{ 44 return unlink(path); 45} 46 47int HalFileStat(const char *path, unsigned int *fileSize) 48{ 49 struct stat info = { 0 }; 50 int ret = stat(path, &info); 51 if (ret < 0) { 52 return ret; 53 } else { 54 return info.st_size; 55 } 56} 57 58int HalFileSeek(int fd, int offset, unsigned int whence) 59{ 60 return lseek(fd, offset, whence); 61}