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