Debian Codegraph @

src/Tools.cpp

raw
1 /*
2 * Copyright (C) 2010-2021 Team Kodi (https://kodi.tv)
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 * See LICENSE.md for more information.
6 */
7
8 #include "Tools.h"
9
10 #ifndef TARGET_WINDOWS
11 #define TYP_INIT 0
12 #define TYP_SMLE 1
13 #define TYP_BIGE 2
14
15 // need to check for ntohll definition
16 // as it was added in iOS SDKs since 8.0
17 #if !defined(ntohll)
18 uint64_t ntohll(uint64_t a)
19 {
20 return htonll(a);
21 }
22 #endif
23
24 #if !defined(htonll)
25 uint64_t htonll(uint64_t a)
26 {
27 static int typ = TYP_INIT;
28 unsigned char c;
29 union
30 {
31 uint64_t ull;
32 unsigned char c[8];
33 } x;
34 if (typ == TYP_INIT)
35 {
36 x.ull = 0x01;
37 typ = (x.c[7] == 0x01ULL) ? TYP_BIGE : TYP_SMLE;
38 }
39 if (typ == TYP_BIGE)
40 return a;
41 x.ull = a;
42 c = x.c[0];
43 x.c[0] = x.c[7];
44 x.c[7] = c;
45 c = x.c[1];
46 x.c[1] = x.c[6];
47 x.c[6] = c;
48 c = x.c[2];
49 x.c[2] = x.c[5];
50 x.c[5] = c;
51 c = x.c[3];
52 x.c[3] = x.c[4];
53 x.c[4] = c;
54 return x.ull;
55 }
56 #endif
57 #endif