• 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 #ifndef INIT_UTILS_H
17 #define INIT_UTILS_H
18 #include <fcntl.h>
19 #include <sys/stat.h>
20 #include <unistd.h>
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 
28 typedef struct {
29     char *name;
30     int value;
31 } InitArgInfo;
32 
33 #define BINARY_BASE 2
34 #define OCTAL_BASE 8
35 #define DECIMAL_BASE 10
36 #define WAIT_MAX_SECOND 5
37 #define MAX_BUFFER_LEN 256
38 #define ARRAY_LENGTH(array) (sizeof((array)) / sizeof((array)[0]))
39 
40 uid_t DecodeUid(const char *name);
41 char *ReadFileToBuf(const char *configFile);
42 int GetProcCmdlineValue(const char *name, const char *buffer, char *value, int length);
43 char *ReadFileData(const char *fileName);
44 
45 int SplitString(char *srcPtr, const char *del, char **dstPtr, int maxNum);
46 void WaitForFile(const char *source, unsigned int maxSecond);
47 size_t WriteAll(int fd, const char *buffer, size_t size);
48 char *GetRealPath(const char *source);
49 int StringToInt(const char *str, int defaultValue);
50 int MakeDirRecursive(const char *dir, mode_t mode);
51 int MakeDir(const char *dir, mode_t mode);
52 int ReadFileInDir(const char *dirPath, const char *includeExt,
53     int (*processFile)(const char *fileName, void *context), void *context);
54 char **SplitStringExt(char *buffer, const char *del, int *returnCount, int maxItemCount);
55 void FreeStringVector(char **vector, int count);
56 int InUpdaterMode(void);
57 int StringReplaceChr(char *strl, char oldChr, char newChr);
58 
59 int GetMapValue(const char *name, const InitArgInfo *infos, int argNum, int defValue);
60 const InitArgInfo *GetServieStatusMap(int *size);
61 #ifdef __cplusplus
62 #if __cplusplus
63 }
64 #endif
65 #endif
66 #endif // INIT_UTILS_H
67