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#ifndef SOFTBUS_ADAPTER_FILE_H
17#define SOFTBUS_ADAPTER_FILE_H
18
19#include <stdint.h>
20
21#ifdef __cplusplus
22#if __cplusplus
23extern "C" {
24#endif
25#endif
26
27#define SOFTBUS_PATH_SEPRATOR '/'
28#define SOFTBUS_MAX_PATH_LEN 256
29
30/* unistd.h */
31#define SOFTBUS_F_OK (0)
32#define SOFTBUS_X_OK (1)
33#define SOFTBUS_W_OK (2)
34#define SOFTBUS_R_OK (4)
35
36/* fcntl.h */
37#define SOFTBUS_O_RDONLY (00)
38#define SOFTBUS_O_WRONLY (01)
39#define SOFTBUS_O_RDWR (02)
40#define SOFTBUS_O_CREATE (0100)
41#define SOFTBUS_O_TRUNC (01000)
42
43#define SOFTBUS_S_IRUSR (0400)
44#define SOFTBUS_S_IWUSR (0200)
45#define SOFTBUS_S_IXUSR (0100)
46/* File operation */
47int32_t SoftBusReadFile(int32_t fd, void *readBuf, uint32_t maxLen);
48int32_t SoftBusReadFullFile(const char *fileName, char *readBuf, uint32_t maxLen);
49int32_t SoftBusWriteFile(const char *fileName, const char *writeBuf, uint32_t len);
50int32_t SoftBusWriteFileFd(int32_t fd, const char *writeBuf, uint32_t len);
51int32_t SoftBusOpenFile(const char *fileName, int32_t flags);
52int32_t SoftBusOpenFileWithPerms(const char *fileName, int32_t flags, int32_t perms);
53void SoftBusRemoveFile(const char *fileName);
54void SoftBusCloseFile(int32_t fd);
55int64_t SoftBusPreadFile(int32_t fd, void *buf, uint64_t readBytes, uint64_t offset);
56int64_t SoftBusPwriteFile(int32_t fd, const void *buf, uint64_t writeBytes, uint64_t offset);
57int32_t SoftBusAccessFile(const char *pathName, int32_t mode);
58int32_t SoftBusMakeDir(const char *pathName, int32_t mode);
59int32_t SoftBusGetFileSize(const char *fileName, uint64_t *fileSize);
60char *SoftBusRealPath(const char *path, char *absPath);
61int32_t SoftBusReadFullFileAndSize(const char *fileName, char *readBuf, uint32_t maxLen, int32_t *size);
62
63#ifdef __cplusplus
64#if __cplusplus
65}
66#endif /* __cplusplus */
67#endif /* __cplusplus */
68
69#endif // SOFTBUS_ADAPTER_FILE_H