[4073] | 1 | //byteorder.h: |
---|
| 2 | |
---|
| 3 | /* |
---|
[6052] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2015 |
---|
[4073] | 5 | * |
---|
| 6 | * This file is part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU Lesser General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU Lesser General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU Lesser General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
| 23 | * |
---|
| 24 | * NOTE: Even though this file is LGPLed it (may) include GPLed files |
---|
| 25 | * so the license of this file is/may therefore downgraded to GPL. |
---|
| 26 | * See HACKING for details. |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #ifndef _ROARAUDIO_BYTEORDER_H_ |
---|
| 30 | #define _ROARAUDIO_BYTEORDER_H_ |
---|
| 31 | |
---|
[4274] | 32 | #define _ROAR_MOVE_BYTE(x,p,n) ( \ |
---|
[4284] | 33 | ((uint_least64_t)( \ |
---|
| 34 | ((uint_least64_t)((uint_least64_t)(x) & ((uint_least64_t)0xFFUL << (8*(p))))) >> (8*(p)) \ |
---|
[4274] | 35 | )) << ((n)-8*((p)+1)) \ |
---|
| 36 | ) |
---|
[4073] | 37 | |
---|
| 38 | #if BYTE_ORDER == BIG_ENDIAN && !defined(ROAR_TARGET_WIN32) |
---|
| 39 | |
---|
| 40 | #define ROAR_NET2HOST64(x) (x) |
---|
| 41 | #define ROAR_HOST2NET64(x) (x) |
---|
| 42 | #define ROAR_NET2HOST32(x) (x) |
---|
| 43 | #define ROAR_HOST2NET32(x) (x) |
---|
| 44 | #define ROAR_NET2HOST16(x) (x) |
---|
| 45 | #define ROAR_HOST2NET16(x) (x) |
---|
| 46 | |
---|
| 47 | #define ROAR_BE2HOST64(x) (x) |
---|
| 48 | #define ROAR_HOST2BE64(x) (x) |
---|
| 49 | #define ROAR_BE2HOST32(x) (x) |
---|
| 50 | #define ROAR_HOST2BE32(x) (x) |
---|
| 51 | #define ROAR_BE2HOST16(x) (x) |
---|
| 52 | #define ROAR_HOST2BE16(x) (x) |
---|
| 53 | |
---|
| 54 | #define ROAR_LE2HOST32(x) ROAR_HOST2LE32(x) |
---|
| 55 | #define ROAR_HOST2LE32(x) (_ROAR_MOVE_BYTE((x), 0, 32) | _ROAR_MOVE_BYTE((x), 1, 32) | \ |
---|
| 56 | _ROAR_MOVE_BYTE((x), 2, 32) | _ROAR_MOVE_BYTE((x), 3, 32) ) |
---|
| 57 | #define ROAR_LE2HOST16(x) ROAR_HOST2LE16(x) |
---|
| 58 | #define ROAR_HOST2LE16(x) (_ROAR_MOVE_BYTE((x), 0, 16) | _ROAR_MOVE_BYTE((x), 1, 16) ) |
---|
| 59 | |
---|
| 60 | //#elif BYTE_ORDER == LITTLE_ENDIAN |
---|
| 61 | #else |
---|
| 62 | #if BYTE_ORDER == LITTLE_ENDIAN |
---|
| 63 | #define ROAR_NET2HOST64(x) ROAR_HOST2NET64(x) |
---|
[4284] | 64 | #define ROAR_HOST2NET64(x) ((uint_least64_t) \ |
---|
[4274] | 65 | (_ROAR_MOVE_BYTE((x), 0, 64) | _ROAR_MOVE_BYTE((x), 1, 64) | \ |
---|
| 66 | _ROAR_MOVE_BYTE((x), 2, 64) | _ROAR_MOVE_BYTE((x), 3, 64) | \ |
---|
| 67 | _ROAR_MOVE_BYTE((x), 4, 64) | _ROAR_MOVE_BYTE((x), 5, 64) | \ |
---|
| 68 | _ROAR_MOVE_BYTE((x), 6, 64) | _ROAR_MOVE_BYTE((x), 7, 64) ) ) |
---|
[4073] | 69 | #else |
---|
| 70 | /* PDP byte order */ |
---|
| 71 | #endif |
---|
| 72 | |
---|
| 73 | #define ROAR_NET2HOST32(x) ntohl((x)) |
---|
| 74 | #define ROAR_HOST2NET32(x) htonl((x)) |
---|
| 75 | #define ROAR_NET2HOST16(x) ntohs((x)) |
---|
| 76 | #define ROAR_HOST2NET16(x) htons((x)) |
---|
| 77 | |
---|
| 78 | #define ROAR_BE2HOST32(x) ntohl(x) |
---|
| 79 | #define ROAR_HOST2BE32(x) htonl(x) |
---|
| 80 | #define ROAR_BE2HOST16(x) ntohs(x) |
---|
| 81 | #define ROAR_HOST2BE16(x) htons(x) |
---|
| 82 | |
---|
| 83 | #define ROAR_LE2HOST64(x) (x) |
---|
| 84 | #define ROAR_HOST2LE64(x) (x) |
---|
| 85 | #define ROAR_LE2HOST32(x) (x) |
---|
| 86 | #define ROAR_HOST2LE32(x) (x) |
---|
| 87 | #define ROAR_LE2HOST16(x) (x) |
---|
| 88 | #define ROAR_HOST2LE16(x) (x) |
---|
| 89 | |
---|
| 90 | #endif |
---|
| 91 | |
---|
| 92 | #endif |
---|
| 93 | |
---|
| 94 | //ll |
---|