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