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