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 
HalFileOpen(const char * path,int oflag,int mode)21 int HalFileOpen(const char *path, int oflag, int mode)
22 {
23     (void)mode;
24     return open(path, oflag);
25 }
26 
HalFileClose(int fd)27 int HalFileClose(int fd)
28 {
29     return close(fd);
30 }
31 
HalFileRead(int fd,char * buf,unsigned int len)32 int HalFileRead(int fd, char *buf, unsigned int len)
33 {
34     return read(fd, buf, len);
35 }
36 
HalFileWrite(int fd,const char * buf,unsigned int len)37 int HalFileWrite(int fd, const char *buf, unsigned int len)
38 {
39     return write(fd, buf, len);
40 }
41 
HalFileDelete(const char * path)42 int HalFileDelete(const char *path)
43 {
44     return unlink(path);
45 }
46 
HalFileStat(const char * path,unsigned int * fileSize)47 int 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 
HalFileSeek(int fd,int offset,unsigned int whence)58 int HalFileSeek(int fd, int offset, unsigned int whence)
59 {
60     return lseek(fd, offset, whence);
61 }