source: roaraudio/include/roaraudio/byteorder.h @ 4073:2e8648011772

Last change on this file since 4073:2e8648011772 was 4073:2e8648011772, checked in by phi, 14 years ago

fixed byte order probelms on some BE platforms with libdnet

File size: 3.0 KB
Line 
1//byteorder.h:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
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
32#define _ROAR_MOVE_BYTE(x,p,n) (((x) & (0xFFUL << (8*(p)))) >> (8*(p)) << ((n)-8*((p)+1)))
33
34#if BYTE_ORDER == BIG_ENDIAN && !defined(ROAR_TARGET_WIN32)
35
36#define ROAR_NET2HOST64(x) (x)
37#define ROAR_HOST2NET64(x) (x)
38#define ROAR_NET2HOST32(x) (x)
39#define ROAR_HOST2NET32(x) (x)
40#define ROAR_NET2HOST16(x) (x)
41#define ROAR_HOST2NET16(x) (x)
42
43#define ROAR_BE2HOST64(x) (x)
44#define ROAR_HOST2BE64(x) (x)
45#define ROAR_BE2HOST32(x) (x)
46#define ROAR_HOST2BE32(x) (x)
47#define ROAR_BE2HOST16(x) (x)
48#define ROAR_HOST2BE16(x) (x)
49
50#define ROAR_LE2HOST32(x) ROAR_HOST2LE32(x)
51#define ROAR_HOST2LE32(x) (_ROAR_MOVE_BYTE((x), 0, 32) | _ROAR_MOVE_BYTE((x), 1, 32) | \
52                           _ROAR_MOVE_BYTE((x), 2, 32) | _ROAR_MOVE_BYTE((x), 3, 32) )
53#define ROAR_LE2HOST16(x) ROAR_HOST2LE16(x)
54#define ROAR_HOST2LE16(x) (_ROAR_MOVE_BYTE((x), 0, 16) | _ROAR_MOVE_BYTE((x), 1, 16) )
55
56//#elif BYTE_ORDER == LITTLE_ENDIAN
57#else
58#if BYTE_ORDER == LITTLE_ENDIAN
59#define ROAR_NET2HOST64(x) ROAR_HOST2NET64(x)
60#define ROAR_HOST2NET64(x) (_ROAR_MOVE_BYTE((x), 0, 64) | _ROAR_MOVE_BYTE((x), 1, 64) | \
61                            _ROAR_MOVE_BYTE((x), 2, 64) | _ROAR_MOVE_BYTE((x), 3, 64) | \
62                            _ROAR_MOVE_BYTE((x), 4, 64) | _ROAR_MOVE_BYTE((x), 5, 64) | \
63                            _ROAR_MOVE_BYTE((x), 6, 64) | _ROAR_MOVE_BYTE((x), 7, 64) )
64#else
65/* PDP byte order */
66#endif
67
68#define ROAR_NET2HOST32(x) ntohl((x))
69#define ROAR_HOST2NET32(x) htonl((x))
70#define ROAR_NET2HOST16(x) ntohs((x))
71#define ROAR_HOST2NET16(x) htons((x))
72
73#define ROAR_BE2HOST32(x) ntohl(x)
74#define ROAR_HOST2BE32(x) htonl(x)
75#define ROAR_BE2HOST16(x) ntohs(x)
76#define ROAR_HOST2BE16(x) htons(x)
77
78#define ROAR_LE2HOST64(x) (x)
79#define ROAR_HOST2LE64(x) (x)
80#define ROAR_LE2HOST32(x) (x)
81#define ROAR_HOST2LE32(x) (x)
82#define ROAR_LE2HOST16(x) (x)
83#define ROAR_HOST2LE16(x) (x)
84
85#endif
86
87#endif
88
89//ll
Note: See TracBrowser for help on using the repository browser.