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
SoftBusWriteFileFd(int32_t fd,const char * writeBuf,uint32_t len)88 int32_t SoftBusWriteFileFd(int32_t fd, const char *writeBuf, uint32_t len)
89 {
90 (void)fd;
91 (void)writeBuf;
92 (void)len;
93 return SOFTBUS_INVALID_FD;
94 }
95
SoftBusOpenFile(const char * fileName,int32_t flags)96 int32_t SoftBusOpenFile(const char *fileName, int32_t flags)
97 {
98 (void)fileName;
99 (void)flags;
100 return SOFTBUS_INVALID_FD;
101 }
102
SoftBusOpenFileWithPerms(const char * fileName,int32_t flags,int32_t perms)103 int32_t SoftBusOpenFileWithPerms(const char *fileName, int32_t flags, int32_t perms)
104 {
105 (void)fileName;
106 (void)flags;
107 (void)perms;
108 return SOFTBUS_INVALID_FD;
109 }
110
SoftBusRemoveFile(const char * fileName)111 void SoftBusRemoveFile(const char *fileName)
112 {
113 (void)fileName;
114 return;
115 }
116
SoftBusCloseFile(int32_t fd)117 void SoftBusCloseFile(int32_t fd)
118 {
119 (void)fd;
120 return;
121 }
122
SoftBusPreadFile(int32_t fd,void * buf,uint64_t readBytes,uint64_t offset)123 int64_t SoftBusPreadFile(int32_t fd, void *buf, uint64_t readBytes, uint64_t offset)
124 {
125 (void)fd;
126 (void)buf;
127 (void)readBytes;
128 (void)offset;
129 return -1;
130 }
131
SoftBusPwriteFile(int32_t fd,const void * buf,uint64_t writeBytes,uint64_t offset)132 int64_t SoftBusPwriteFile(int32_t fd, const void *buf, uint64_t writeBytes, uint64_t offset)
133 {
134 (void)fd;
135 (void)buf;
136 (void)writeBytes;
137 (void)offset;
138 return -1;
139 }
140
SoftBusAccessFile(const char * pathName,int32_t mode)141 int32_t SoftBusAccessFile(const char *pathName, int32_t mode)
142 {
143 (void)pathName;
144 (void)mode;
145 return SOFTBUS_ERR;
146 }
147
SoftBusMakeDir(const char * pathName,int32_t mode)148 int32_t SoftBusMakeDir(const char *pathName, int32_t mode)
149 {
150 (void)pathName;
151 (void)mode;
152 return SOFTBUS_ADAPTER_ERR;
153 }
SoftBusGetFileSize(const char * fileName,uint64_t * fileSize)154 int32_t SoftBusGetFileSize(const char *fileName, uint64_t *fileSize)
155 {
156 (void)fileName;
157 (void)fileSize;
158 return SOFTBUS_ERR;
159 }
160
SoftBusRealPath(const char * path,char * absPath)161 char *SoftBusRealPath(const char *path, char *absPath)
162 {
163 (void)path;
164 (void)absPath;
165 return NULL;
166 }
167