this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

CoreServices: Core Endian implementation

+342
+1
src/CoreServices/CMakeLists.txt
··· 18 18 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../util) 19 19 20 20 set(CoreServices_SRCS 21 + CoreEndian.cpp 21 22 Multiprocessing.cpp 22 23 TextUtils.cpp 23 24 MacMemory.cpp
+264
src/CoreServices/CoreEndian.cpp
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2013 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #include "CoreEndian.h" 21 + #include <endian.h> 22 + #include <stdint.h> 23 + 24 + template <typename T> T bswap(T value); 25 + 26 + template <> uint16_t bswap(uint16_t value) 27 + { 28 + return __builtin_bswap16(value); 29 + } 30 + 31 + template <> uint32_t bswap(uint32_t value) 32 + { 33 + return __builtin_bswap32(value); 34 + } 35 + 36 + template <> uint64_t bswap(uint64_t value) 37 + { 38 + return __builtin_bswap64(value); 39 + } 40 + 41 + template <typename T> T LtoN(T value) 42 + { 43 + #if __BYTE_ORDER == __LITTLE_ENDIAN 44 + return value; 45 + #else 46 + return bswap(value); 47 + #endif 48 + } 49 + 50 + template <typename T> T BtoN(T value) 51 + { 52 + #if __BYTE_ORDER == __BIG_ENDIAN 53 + return value; 54 + #else 55 + return bswap(value); 56 + #endif 57 + } 58 + 59 + template <typename T> T NtoL(T value) 60 + { 61 + return LtoN(value); 62 + } 63 + 64 + template <typename T> T NtoB(T value) 65 + { 66 + return BtoN(value); 67 + } 68 + 69 + UInt16 Endian16_Swap(UInt16 value) 70 + { 71 + return bswap(value); 72 + } 73 + 74 + UInt32 Endian32_Swap(UInt32 value) 75 + { 76 + return bswap(value); 77 + } 78 + 79 + UInt64 Endian64_Swap(UInt64 value) 80 + { 81 + return bswap(value); 82 + } 83 + 84 + SInt16 EndianS16_BtoL(SInt16 value) 85 + { 86 + return bswap(value); 87 + } 88 + 89 + SInt16 EndianS16_BtoN(SInt16 value) 90 + { 91 + return BtoN(value); 92 + } 93 + 94 + SInt16 EndianS16_LtoB(SInt16 value) 95 + { 96 + return bswap(value); 97 + } 98 + 99 + SInt16 EndianS16_LtoN(SInt16 value) 100 + { 101 + return LtoN(value); 102 + } 103 + 104 + SInt16 EndianS16_NtoB(SInt16 value) 105 + { 106 + return NtoB(value); 107 + } 108 + 109 + SInt16 EndianS16_NtoL(SInt16 value) 110 + { 111 + return NtoL(value); 112 + } 113 + 114 + SInt32 EndianS32_BtoL(SInt32 value) 115 + { 116 + return bswap(value); 117 + } 118 + 119 + SInt32 EndianS32_BtoN(SInt32 value) 120 + { 121 + return BtoN(value); 122 + } 123 + 124 + SInt32 EndianS32_LtoB(SInt32 value) 125 + { 126 + return bswap(value); 127 + } 128 + 129 + SInt32 EndianS32_LtoN(SInt32 value) 130 + { 131 + return LtoN(value); 132 + } 133 + 134 + SInt32 EndianS32_NtoB(SInt32 value) 135 + { 136 + return NtoB(value); 137 + } 138 + 139 + SInt32 EndianS32_NtoL(SInt32 value) 140 + { 141 + return NtoL(value); 142 + } 143 + 144 + 145 + SInt64 EndianS64_BtoL(SInt64 value) 146 + { 147 + return bswap(value); 148 + } 149 + 150 + SInt64 EndianS64_BtoN(SInt64 value) 151 + { 152 + return BtoN(value); 153 + } 154 + 155 + SInt64 EndianS64_LtoB(SInt64 value) 156 + { 157 + return bswap(value); 158 + } 159 + 160 + SInt64 EndianS64_LtoN(SInt64 value) 161 + { 162 + return LtoN(value); 163 + } 164 + 165 + SInt64 EndianS64_NtoB(SInt64 value) 166 + { 167 + return NtoB(value); 168 + } 169 + 170 + SInt64 EndianS64_NtoL(SInt64 value) 171 + { 172 + return NtoL(value); 173 + } 174 + 175 + UInt16 EndianU16_BtoL(UInt16 value) 176 + { 177 + return bswap(value); 178 + } 179 + 180 + UInt16 EndianU16_BtoN(UInt16 value) 181 + { 182 + return BtoN(value); 183 + } 184 + 185 + UInt16 EndianU16_LtoB(UInt16 value) 186 + { 187 + return bswap(value); 188 + } 189 + 190 + UInt16 EndianU16_LtoN(UInt16 value) 191 + { 192 + return LtoN(value); 193 + } 194 + 195 + UInt16 EndianU16_NtoB(UInt16 value) 196 + { 197 + return NtoB(value); 198 + } 199 + 200 + UInt16 EndianU16_NtoL(UInt16 value) 201 + { 202 + return NtoL(value); 203 + } 204 + 205 + UInt32 EndianU32_BtoL(UInt32 value) 206 + { 207 + return bswap(value); 208 + } 209 + 210 + UInt32 EndianU32_BtoN(UInt32 value) 211 + { 212 + return BtoN(value); 213 + } 214 + 215 + UInt32 EndianU32_LtoB(UInt32 value) 216 + { 217 + return bswap(value); 218 + } 219 + 220 + UInt32 EndianU32_LtoN(UInt32 value) 221 + { 222 + return LtoN(value); 223 + } 224 + 225 + UInt32 EndianU32_NtoB(UInt32 value) 226 + { 227 + return NtoB(value); 228 + } 229 + 230 + UInt32 EndianU32_NtoL(UInt32 value) 231 + { 232 + return NtoL(value); 233 + } 234 + 235 + UInt64 EndianU64_BtoL(UInt64 value) 236 + { 237 + return bswap(value); 238 + } 239 + 240 + UInt64 EndianU64_BtoN(UInt64 value) 241 + { 242 + return BtoN(value); 243 + } 244 + 245 + UInt64 EndianU64_LtoB(UInt64 value) 246 + { 247 + return bswap(value); 248 + } 249 + 250 + UInt64 EndianU64_LtoN(UInt64 value) 251 + { 252 + return LtoN(value); 253 + } 254 + 255 + UInt64 EndianU64_NtoB(UInt64 value) 256 + { 257 + return NtoB(value); 258 + } 259 + 260 + UInt64 EndianU64_NtoL(UInt64 value) 261 + { 262 + return NtoL(value); 263 + } 264 +
+75
src/CoreServices/CoreEndian.h
··· 1 + /* 2 + This file is part of Darling. 3 + 4 + Copyright (C) 2013 Lubos Dolezel 5 + 6 + Darling is free software: you can redistribute it and/or modify 7 + it under the terms of the GNU General Public License as published by 8 + the Free Software Foundation, either version 3 of the License, or 9 + (at your option) any later version. 10 + 11 + Darling is distributed in the hope that it will be useful, 12 + but WITHOUT ANY WARRANTY; without even the implied warranty of 13 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 + GNU General Public License for more details. 15 + 16 + You should have received a copy of the GNU General Public License 17 + along with Darling. If not, see <http://www.gnu.org/licenses/>. 18 + */ 19 + 20 + #ifndef COREENDIAN_H 21 + #define COREENDIAN_H 22 + #include "MacTypes.h" 23 + 24 + extern "C" 25 + { 26 + 27 + UInt16 Endian16_Swap(UInt16 value); 28 + UInt32 Endian32_Swap(UInt32 value); 29 + UInt64 Endian64_Swap(UInt64 value); 30 + 31 + SInt16 EndianS16_BtoL(SInt16 value); 32 + SInt16 EndianS16_BtoN(SInt16 value); 33 + SInt16 EndianS16_LtoB(SInt16 value); 34 + SInt16 EndianS16_LtoN(SInt16 value); 35 + SInt16 EndianS16_NtoB(SInt16 value); 36 + SInt16 EndianS16_NtoL(SInt16 value); 37 + 38 + SInt32 EndianS32_BtoL(SInt32 value); 39 + SInt32 EndianS32_BtoN(SInt32 value); 40 + SInt32 EndianS32_LtoB(SInt32 value); 41 + SInt32 EndianS32_LtoN(SInt32 value); 42 + SInt32 EndianS32_NtoB(SInt32 value); 43 + SInt32 EndianS32_NtoL(SInt32 value); 44 + 45 + SInt64 EndianS64_BtoL(SInt64 value); 46 + SInt64 EndianS64_BtoN(SInt64 value); 47 + SInt64 EndianS64_LtoB(SInt64 value); 48 + SInt64 EndianS64_LtoN(SInt64 value); 49 + SInt64 EndianS64_NtoB(SInt64 value); 50 + SInt64 EndianS64_NtoL(SInt64 value); 51 + 52 + UInt16 EndianU16_BtoL(UInt16 value); 53 + UInt16 EndianU16_BtoN(UInt16 value); 54 + UInt16 EndianU16_LtoB(UInt16 value); 55 + UInt16 EndianU16_LtoN(UInt16 value); 56 + UInt16 EndianU16_NtoB(UInt16 value); 57 + UInt16 EndianU16_NtoL(UInt16 value); 58 + 59 + UInt32 EndianU32_BtoL(UInt32 value); 60 + UInt32 EndianU32_BtoN(UInt32 value); 61 + UInt32 EndianU32_LtoB(UInt32 value); 62 + UInt32 EndianU32_LtoN(UInt32 value); 63 + UInt32 EndianU32_NtoB(UInt32 value); 64 + UInt32 EndianU32_NtoL(UInt32 value); 65 + 66 + UInt64 EndianU64_BtoL(UInt64 value); 67 + UInt64 EndianU64_BtoN(UInt64 value); 68 + UInt64 EndianU64_LtoB(UInt64 value); 69 + UInt64 EndianU64_LtoN(UInt64 value); 70 + UInt64 EndianU64_NtoB(UInt64 value); 71 + UInt64 EndianU64_NtoL(UInt64 value); 72 + 73 + } 74 + 75 + #endif
+2
src/CoreServices/MacTypes.h
··· 9 9 typedef uint16_t UInt16; 10 10 typedef int32_t SInt32; 11 11 typedef uint32_t UInt32; 12 + typedef int64_t SInt64; 13 + typedef uint64_t UInt64; 12 14 13 15 typedef uint32_t OptionBits; 14 16