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 OHOS_STORAGE_DAEMON_ENDIAN_H
16 #define OHOS_STORAGE_DAEMON_ENDIAN_H
17 
IsLe()18 inline bool IsLe()
19 {
20     int tmp = 0x01;
21     return *(char *)&tmp;
22 }
23 
IsBe()24 inline bool IsBe()
25 {
26     int tmp = 0x01;
27     return *((char *)&tmp + sizeof(tmp) - 1);
28 }
29 
30 /* We haven't meet any BE machine, so leave it until we really need it. */
31 template <typename T>
LeToCpu(T x)32 inline T LeToCpu(T x)
33 {
34     return x;
35 }
36 
37 template <typename T>
CpuToLe(T x)38 inline T CpuToLe(T x)
39 {
40     return x;
41 }
42 
43 #endif // OHOS_STORAGE_DAEMON_ENDIAN_H
44