• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef CLIENT_TRANS_PROXY_FILE_COMMON_H
17 #define CLIENT_TRANS_PROXY_FILE_COMMON_H
18 
19 #include <stdint.h>
20 
21 #define MAX_FILE_PATH_NAME_LEN 512
22 #define INVALID_FD (-1)
23 
24 #define SOFTBUS_F_RDLCK 0
25 #define SOFTBUS_F_WRLCK 1
26 
27 #define BYTE_INT_NUM 4
28 #define BIT_INT_NUM 32
29 #define BIT_BYTE_NUM 8
30 
31 #define FRAME_NUM_0 0
32 #define FRAME_NUM_1 1
33 #define FRAME_NUM_2 2
34 
35 #define PATH_SEPARATOR '/'
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 typedef struct {
42     uint8_t *buffer;
43     uint32_t bufferSize;
44 } FileListBuffer;
45 
46 bool IsPathValid(char *filePath);
47 int32_t GetAndCheckRealPath(const char *filePath, char *absPath);
48 bool CheckDestFilePathValid(const char *destFile);
49 int32_t FrameIndexToType(uint64_t index, uint64_t frameNumber);
50 
51 char *BufferToFileList(uint8_t *buffer, uint32_t bufferSize, int32_t *fileCount);
52 int32_t FileListToBuffer(const char **destFile, uint32_t fileCnt, FileListBuffer *outbufferInfo);
53 
54 const char* TransGetFileName(const char* path);
55 
56 uint16_t RTU_CRC(const unsigned char *puchMsg, uint16_t usDataLen);
57 
58 int32_t FileLock(int32_t fd, int32_t type, bool isBlock);
59 int32_t TryFileLock(int32_t fd, int32_t type, int32_t retryTimes);
60 int32_t FileUnLock(int32_t fd);
61 
62 #ifdef __cplusplus
63 }
64 #endif
65 
66 #endif