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 DISTRIBUTEDDATAMGR_NATIVERDB_RDB_PLATFORM_H 17 #define DISTRIBUTEDDATAMGR_NATIVERDB_RDB_PLATFORM_H 18 19 #include <sys/stat.h> 20 21 #include <cstdint> 22 #include <string> 23 24 #include "unistd.h" 25 #ifdef WINDOWS_PLATFORM 26 #include <dir.h> 27 #endif 28 #define UNUSED_FUNCTION __attribute__((unused)) 29 namespace OHOS { 30 namespace NativeRdb { 31 static constexpr mode_t DIR_RIGHT = 0771; GetUid()32static UNUSED_FUNCTION uint32_t GetUid() 33 { 34 #ifdef WINDOWS_PLATFORM 35 return 0; 36 #else 37 return getuid(); 38 #endif 39 } 40 41 static UNUSED_FUNCTION int MkDir(const std::string &filePath, mode_t dirRight = DIR_RIGHT) 42 { 43 #ifdef WINDOWS_PLATFORM 44 return mkdir(filePath.c_str()); 45 #else 46 return mkdir(filePath.c_str(), dirRight); 47 #endif 48 } 49 GetThreadId()50static UNUSED_FUNCTION uint64_t GetThreadId() 51 { 52 #ifdef WINDOWS_PLATFORM 53 return 0; 54 #else 55 return (uint64_t)pthread_self(); 56 #endif 57 } 58 59 } // namespace NativeRdb 60 } // namespace OHOS 61 #endif