1*9f988b79SJean-Baptiste Boric /* $NetBSD: udf_bswap.h,v 1.8 2009/10/22 21:50:01 bouyer Exp $ */
2*9f988b79SJean-Baptiste Boric
3*9f988b79SJean-Baptiste Boric /*
4*9f988b79SJean-Baptiste Boric * Copyright (c) 1998 Manuel Bouyer.
5*9f988b79SJean-Baptiste Boric *
6*9f988b79SJean-Baptiste Boric * Redistribution and use in source and binary forms, with or without
7*9f988b79SJean-Baptiste Boric * modification, are permitted provided that the following conditions
8*9f988b79SJean-Baptiste Boric * are met:
9*9f988b79SJean-Baptiste Boric * 1. Redistributions of source code must retain the above copyright
10*9f988b79SJean-Baptiste Boric * notice, this list of conditions and the following disclaimer.
11*9f988b79SJean-Baptiste Boric * 2. Redistributions in binary form must reproduce the above copyright
12*9f988b79SJean-Baptiste Boric * notice, this list of conditions and the following disclaimer in the
13*9f988b79SJean-Baptiste Boric * documentation and/or other materials provided with the distribution.
14*9f988b79SJean-Baptiste Boric *
15*9f988b79SJean-Baptiste Boric * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*9f988b79SJean-Baptiste Boric * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*9f988b79SJean-Baptiste Boric * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*9f988b79SJean-Baptiste Boric * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*9f988b79SJean-Baptiste Boric * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*9f988b79SJean-Baptiste Boric * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*9f988b79SJean-Baptiste Boric * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*9f988b79SJean-Baptiste Boric * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*9f988b79SJean-Baptiste Boric * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*9f988b79SJean-Baptiste Boric * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*9f988b79SJean-Baptiste Boric *
26*9f988b79SJean-Baptiste Boric * adapted for UDF by Reinoud Zandijk <reinoud@netbsd.org>
27*9f988b79SJean-Baptiste Boric *
28*9f988b79SJean-Baptiste Boric */
29*9f988b79SJean-Baptiste Boric
30*9f988b79SJean-Baptiste Boric #ifndef _FS_UDF_UDF_BSWAP_H_
31*9f988b79SJean-Baptiste Boric #define _FS_UDF_UDF_BSWAP_H_
32*9f988b79SJean-Baptiste Boric
33*9f988b79SJean-Baptiste Boric #include <sys/endian.h>
34*9f988b79SJean-Baptiste Boric #include <machine/bswap.h>
35*9f988b79SJean-Baptiste Boric #include <sys/bswap.h>
36*9f988b79SJean-Baptiste Boric
37*9f988b79SJean-Baptiste Boric /* rest only relevant for big endian machines */
38*9f988b79SJean-Baptiste Boric #if (BYTE_ORDER == BIG_ENDIAN)
39*9f988b79SJean-Baptiste Boric
40*9f988b79SJean-Baptiste Boric /* inlines for access to swapped data */
41*9f988b79SJean-Baptiste Boric static __inline uint16_t udf_rw16(uint16_t);
42*9f988b79SJean-Baptiste Boric static __inline uint32_t udf_rw32(uint32_t);
43*9f988b79SJean-Baptiste Boric static __inline uint64_t udf_rw64(uint64_t);
44*9f988b79SJean-Baptiste Boric
45*9f988b79SJean-Baptiste Boric
46*9f988b79SJean-Baptiste Boric static __inline uint16_t
udf_rw16(uint16_t a)47*9f988b79SJean-Baptiste Boric udf_rw16(uint16_t a)
48*9f988b79SJean-Baptiste Boric {
49*9f988b79SJean-Baptiste Boric return bswap16(a);
50*9f988b79SJean-Baptiste Boric }
51*9f988b79SJean-Baptiste Boric
52*9f988b79SJean-Baptiste Boric
53*9f988b79SJean-Baptiste Boric static __inline uint32_t
udf_rw32(uint32_t a)54*9f988b79SJean-Baptiste Boric udf_rw32(uint32_t a)
55*9f988b79SJean-Baptiste Boric {
56*9f988b79SJean-Baptiste Boric return bswap32(a);
57*9f988b79SJean-Baptiste Boric }
58*9f988b79SJean-Baptiste Boric
59*9f988b79SJean-Baptiste Boric
60*9f988b79SJean-Baptiste Boric static __inline uint64_t
udf_rw64(uint64_t a)61*9f988b79SJean-Baptiste Boric udf_rw64(uint64_t a)
62*9f988b79SJean-Baptiste Boric {
63*9f988b79SJean-Baptiste Boric return bswap64(a);
64*9f988b79SJean-Baptiste Boric }
65*9f988b79SJean-Baptiste Boric
66*9f988b79SJean-Baptiste Boric #else
67*9f988b79SJean-Baptiste Boric
68*9f988b79SJean-Baptiste Boric #define udf_rw16(a) ((uint16_t)(a))
69*9f988b79SJean-Baptiste Boric #define udf_rw32(a) ((uint32_t)(a))
70*9f988b79SJean-Baptiste Boric #define udf_rw64(a) ((uint64_t)(a))
71*9f988b79SJean-Baptiste Boric
72*9f988b79SJean-Baptiste Boric #endif
73*9f988b79SJean-Baptiste Boric
74*9f988b79SJean-Baptiste Boric
75*9f988b79SJean-Baptiste Boric #endif /* !_FS_UDF_UDF_BSWAP_H_ */
76*9f988b79SJean-Baptiste Boric
77