1 /*
2  * Copyright (c) 2024 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 IMF_SERVICES_INCLUDE_FILE_OPERATOR_H
17 #define IMF_SERVICES_INCLUDE_FILE_OPERATOR_H
18 
19 #include <fcntl.h>
20 #include <sys/types.h>
21 
22 #include <string>
23 
24 #include "config_policy_utils.h"
25 namespace OHOS {
26 namespace MiscServices {
27 class FileOperator {
28 public:
29     static bool Create(const std::string &path, mode_t mode);
30     static bool IsExist(const std::string &path);
31     static bool Read(const std::string &path, std::string &content);
32     static bool Read(const std::string &path, const std::string &key, std::string &content);
33     static bool Write(
34         const std::string &path, const std::string &content, int32_t flags, mode_t mode = S_IRUSR | S_IWUSR);
35     static std::string GetRealPath(const char *path);
36 
37 private:
38     static constexpr int32_t SUCCESS = 0;
39     static std::string Read(const std::string &path, const std::string &key);
40 };
41 } // namespace MiscServices
42 } // namespace OHOS
43 
44 #endif // IMF_SERVICES_INCLUDE_FILE_OPERATOR_H
45