1 /* @(#)bswap.h	1.3 06/09/13 Copyright 2002 J. Schilling */
2 #ifndef _BSWAP_H
3 #define	_BSWAP_H
4 
5 /*
6  *	Allow to use B2N_* macros found in libdvdread in a portable way.
7  *	These macros should better be avoided as in place conversion in
8  *	general only works on processors like Motorola 68000 and Intel x86.
9  *	Modern processors usually have alignement restrictions that may
10  *	cause problems. The stripped down libdvdread for mkisofs is known
11  *	not to have these alignement problems, so we may use the macros
12  *	as they have been introduced by the authors of libdvdread.
13  *
14  *	Copyright (c) 2002 J. Schilling
15  */
16 /*
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License version 2
19  * as published by the Free Software Foundation.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License along with
27  * this program; see the file COPYING.  If not, write to the Free Software
28  * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29  */
30 
31 #include <schily/mconfig.h>
32 #include <schily/btorder.h>
33 #include <schily/intcvt.h>
34 
35 #if defined(WORDS_BIGENDIAN)
36 
37 /* All bigendian systems are fine, just ignore the swaps. */
38 #define	B2N_16(x) (void)(x)
39 #define	B2N_32(x) (void)(x)
40 #define	B2N_64(x) (void)(x)
41 
42 #else
43 
44 /*
45  * It is a bad idea to convert numbers in place.
46  * In protocols, there is usually the additional problem that the
47  * data is not properly aligned.
48  */
49 #define	B2N_16(x) (x) = a_to_u_2_byte(&(x))
50 #define	B2N_32(x) (x) = a_to_u_4_byte(&(x))
51 #define	B2N_64(x) (x) = a_to_u_8_byte(&(x))
52 
53 #endif
54 
55 #endif /* _BSWAP_H */
56