1 |
dpavlin |
1 |
/* |
2 |
|
|
* libhfs - library for reading and writing Macintosh HFS volumes |
3 |
|
|
* |
4 |
|
|
* Copyright (C) 2000 Klaus Halfmann <klaus.halfmann@feri.de> |
5 |
|
|
* Original work 1996-1998 Robert Leslie <rob@mars.org> |
6 |
|
|
* |
7 |
|
|
* This file defines some byte swapping function. I did not find this |
8 |
|
|
* in any standard or linux way. |
9 |
|
|
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* (at your option) any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program; if not, write to the Free Software |
22 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 |
|
|
* |
24 |
|
|
*/ |
25 |
|
|
|
26 |
|
|
#include "tools/endianess.h" |
27 |
|
|
#include "apple.h" |
28 |
|
|
|
29 |
|
|
/* basic fuction: |
30 |
|
|
value = swab_inc(ptr); |
31 |
|
|
ptr is afterwards incremented by sizeof(value) |
32 |
|
|
*/ |
33 |
|
|
|
34 |
|
|
#define bswap_16(i) createHostInt(&(i), 2, big_endian) |
35 |
|
|
#define bswap_32(i) createHostInt(&(i), 4, big_endian) |
36 |
|
|
#define bswap_64(i) createHostInt64(&(i), 8, big_endian) |
37 |
|
|
|
38 |
|
|
#define bswabU16(val) bswap_16(val) |
39 |
|
|
|
40 |
|
|
static inline UInt8 bswabU8_inc(char **ptr) |
41 |
|
|
{ |
42 |
|
|
UInt8 v = *(UInt8 *)*ptr; |
43 |
|
|
*ptr += 1; |
44 |
|
|
return v; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
static inline UInt16 bswabU16_inc(char **ptr) |
48 |
|
|
{ |
49 |
|
|
UInt16 v = *(UInt16 *)*ptr; |
50 |
|
|
*ptr += 2; |
51 |
|
|
return bswap_16(v); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
static inline UInt32 bswabU32_inc(char **ptr) |
55 |
|
|
{ |
56 |
|
|
UInt32 v = *(UInt32 *)*ptr; |
57 |
|
|
*ptr += 4; |
58 |
|
|
return bswap_32(v); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
static inline APPLEUInt64 bswabU64_inc(char **ptr) |
62 |
|
|
{ |
63 |
|
|
APPLEUInt64 v = *(APPLEUInt64 *)*ptr; |
64 |
|
|
*ptr += 8; |
65 |
|
|
return bswap_64(v); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
static inline void bstoreU8_inc(char **ptr, UInt8 val) |
69 |
|
|
{ |
70 |
|
|
UInt8 **p = (UInt8 **)ptr; |
71 |
|
|
**p = val; |
72 |
|
|
*ptr += 1; |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
static inline void bstoreU16_inc(char **ptr, UInt16 val) |
76 |
|
|
{ |
77 |
|
|
UInt16 **p = (UInt16 **)ptr; |
78 |
|
|
**p = bswap_16(val); |
79 |
|
|
*ptr += 2; |
80 |
|
|
} |
81 |
|
|
|
82 |
|
|
static inline void bstoreU32_inc(char **ptr, UInt32 val) |
83 |
|
|
{ |
84 |
|
|
UInt32 **p = (UInt32 **)ptr; |
85 |
|
|
**p = bswap_32(val); |
86 |
|
|
*ptr += 4; |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
static inline void bstoreU64_inc(char **ptr, APPLEUInt64 val) |
90 |
|
|
{ |
91 |
|
|
APPLEUInt64 **p = (APPLEUInt64 **)ptr; |
92 |
|
|
**p = bswap_64(val); |
93 |
|
|
*ptr += 8; |
94 |
|
|
} |
95 |
|
|
|