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 #ifndef PREFERENCES_FILE_OPERATION_H 16 #define PREFERENCES_FILE_OPERATION_H 17 18 #include <sys/stat.h> 19 #include <unistd.h> 20 #include <string> 21 #include "visibility.h" 22 23 #if defined(WINDOWS_PLATFORM) 24 25 #include <iostream> 26 27 #else 28 29 #include <stdarg.h> 30 31 #if !(defined(MAC_PLATFORM) || defined(ANDROID_PLATFORM) || defined(IOS_PLATFORM)) 32 33 #include <cstdlib> 34 35 #endif 36 37 #endif 38 39 #ifndef FILE_MODE 40 #define FILE_MODE 0771 41 #endif 42 43 #ifndef FILE_EXIST 44 #define FILE_EXIST 0 45 #endif 46 47 #ifndef INT_MAX 48 #define INT_MAX 2147483647 49 #endif 50 51 namespace OHOS { 52 namespace NativePreferences { Mkdir(const std::string & filePath)53static UNUSED_FUNCTION int Mkdir(const std::string &filePath) 54 { 55 #if defined(WINDOWS_PLATFORM) 56 return mkdir(filePath.c_str()); 57 #else 58 return mkdir(filePath.c_str(), FILE_MODE); 59 #endif 60 } 61 Access(const std::string & filePath)62static UNUSED_FUNCTION int Access(const std::string &filePath) 63 { 64 #if defined(WINDOWS_PLATFORM) 65 return _access(filePath.c_str(), FILE_EXIST); 66 #else 67 return access(filePath.c_str(), FILE_EXIST); 68 #endif 69 } 70 } // namespace NativePreferences 71 } // namespace OHOS 72 #endif // PREFERENCES_FILE_OPERATION_H