• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
16 #include "softbus_adapter_file.h"
17 
18 #include "cmsis_os2.h"
19 #include "softbus_adapter_errcode.h"
20 #include "softbus_adapter_log.h"
21 #include "softbus_errcode.h"
22 #include "utils_file.h"
23 
SoftBusReadFile(int32_t fd,void * readBuf,uint32_t maxLen)24 int32_t SoftBusReadFile(int32_t fd, void *readBuf, uint32_t maxLen)
25 {
26     (void)fd;
27     (void)readBuf;
28     (void)maxLen;
29     return -1;
30 }
31 
SoftBusReadFullFile(const char * fileName,char * readBuf,uint32_t maxLen)32 int32_t SoftBusReadFullFile(const char *fileName, char *readBuf, uint32_t maxLen)
33 {
34     if (fileName == NULL || readBuf == NULL || maxLen == 0) {
35         return SOFTBUS_INVALID_PARAM;
36     }
37     uint32_t fileLen = 0;
38     int32_t fd = UtilsFileOpen(fileName, O_RDONLY_FS, 0);
39     if (fd < 0) {
40         HILOG_ERROR(SOFTBUS_HILOG_ID, "Read UtilsFileOpen fail");
41         return SOFTBUS_FILE_ERR;
42     }
43     int32_t ret = UtilsFileStat(fileName, &fileLen);
44     if (ret < 0) {
45         UtilsFileClose(fd);
46         return SOFTBUS_FILE_ERR;
47     }
48     ret = UtilsFileSeek(fd, 0, SEEK_SET_FS);
49     if (ret < 0) {
50         HILOG_ERROR(SOFTBUS_HILOG_ID, "Read UtilsFileSeek fail");
51         UtilsFileClose(fd);
52         return SOFTBUS_FILE_ERR;
53     }
54     if (fileLen > maxLen) {
55         HILOG_ERROR(SOFTBUS_HILOG_ID, "Read file len not legal, clear buf");
56         UtilsFileClose(fd);
57         return SOFTBUS_FILE_ERR;
58     }
59     ret = UtilsFileRead(fd, readBuf, maxLen);
60     if (ret < 0) {
61         HILOG_ERROR(SOFTBUS_HILOG_ID, "Read UtilsFileRead, ret=%{public}d", ret);
62         UtilsFileClose(fd);
63         return SOFTBUS_FILE_ERR;
64     }
65     UtilsFileClose(fd);
66     return SOFTBUS_OK;
67 }
68 
SoftBusWriteFile(const char * fileName,const char * writeBuf,uint32_t len)69 int32_t SoftBusWriteFile(const char *fileName, const char *writeBuf, uint32_t len)
70 {
71     int32_t ret;
72     int32_t fd;
73     fd = UtilsFileOpen(fileName, O_RDWR_FS | O_CREAT_FS | O_TRUNC_FS, 0);
74     if (fd < 0) {
75         HILOG_ERROR(SOFTBUS_HILOG_ID, "UtilsFileOpen fail");
76         return SOFTBUS_FILE_ERR;
77     }
78     ret = UtilsFileWrite(fd, writeBuf, len);
79     if (ret != (int32_t)len) {
80         HILOG_ERROR(SOFTBUS_HILOG_ID, "UtilsFileOpen UtilsFileWrite fail");
81         UtilsFileClose(fd);
82         return SOFTBUS_FILE_ERR;
83     }
84     UtilsFileClose(fd);
85     return SOFTBUS_OK;
86 }
87 
SoftBusOpenFile(const char * fileName,int32_t flags)88 int32_t SoftBusOpenFile(const char *fileName, int32_t flags)
89 {
90     (void)fileName;
91     (void)flags;
92     return SOFTBUS_INVALID_FD;
93 }
94 
SoftBusOpenFileWithPerms(const char * fileName,int32_t flags,int32_t perms)95 int32_t SoftBusOpenFileWithPerms(const char *fileName, int32_t flags, int32_t perms)
96 {
97     (void)fileName;
98     (void)flags;
99     (void)perms;
100     return SOFTBUS_INVALID_FD;
101 }
102 
SoftBusRemoveFile(const char * fileName)103 void SoftBusRemoveFile(const char *fileName)
104 {
105     (void)fileName;
106     return;
107 }
108 
SoftBusCloseFile(int32_t fd)109 void SoftBusCloseFile(int32_t fd)
110 {
111     (void)fd;
112     return;
113 }
114 
SoftBusPreadFile(int32_t fd,void * buf,uint64_t readBytes,uint64_t offset)115 int64_t SoftBusPreadFile(int32_t fd, void *buf, uint64_t readBytes, uint64_t offset)
116 {
117     (void)fd;
118     (void)buf;
119     (void)readBytes;
120     (void)offset;
121     return -1;
122 }
123 
SoftBusPwriteFile(int32_t fd,const void * buf,uint64_t writeBytes,uint64_t offset)124 int64_t SoftBusPwriteFile(int32_t fd, const void *buf, uint64_t writeBytes, uint64_t offset)
125 {
126     (void)fd;
127     (void)buf;
128     (void)writeBytes;
129     (void)offset;
130     return -1;
131 }
132 
SoftBusAccessFile(const char * pathName,int32_t mode)133 int32_t SoftBusAccessFile(const char *pathName, int32_t mode)
134 {
135     (void)pathName;
136     (void)mode;
137     return SOFTBUS_ERR;
138 }
139 
SoftBusMakeDir(const char * pathName,int32_t mode)140 int32_t SoftBusMakeDir(const char *pathName, int32_t mode)
141 {
142     (void)pathName;
143     (void)mode;
144     return SOFTBUS_ADAPTER_ERR;
145 }
SoftBusGetFileSize(const char * fileName,uint64_t * fileSize)146 int32_t SoftBusGetFileSize(const char *fileName, uint64_t *fileSize)
147 {
148     (void)fileName;
149     (void)fileSize;
150     return SOFTBUS_ERR;
151 }
152 
SoftBusRealPath(const char * path,char * absPath)153 char *SoftBusRealPath(const char *path, char *absPath)
154 {
155     (void)path;
156     (void)absPath;
157     return NULL;
158 }
159