1960
|
1 /* |
|
2 |
|
3 Copyright (C) 1996 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_byte_swap_h) |
|
24 #define octave_byte_swap_h 1 |
|
25 |
|
26 static inline void |
|
27 swap_bytes (char *t, unsigned int i, unsigned int j) |
|
28 { |
|
29 char tmp = t[i]; |
|
30 t[i] = t[j]; |
|
31 t[j] = tmp; |
|
32 } |
|
33 |
|
34 static inline void |
|
35 swap_2_bytes (char *t) |
|
36 { |
|
37 swap_bytes (t, 0, 1); |
|
38 } |
|
39 |
|
40 static inline void |
|
41 swap_4_bytes (char *t) |
|
42 { |
|
43 swap_bytes (t, 0, 3); |
|
44 swap_bytes (t, 1, 2); |
|
45 } |
|
46 |
|
47 static inline void |
|
48 swap_8_bytes (char *t) |
|
49 { |
|
50 swap_bytes (t, 0, 7); |
|
51 swap_bytes (t, 1, 6); |
|
52 swap_bytes (t, 2, 5); |
|
53 swap_bytes (t, 3, 4); |
|
54 } |
|
55 |
|
56 static inline void |
|
57 swap_2_bytes (char *t, int len) |
|
58 { |
|
59 char *ptr = t; |
|
60 for (int i = 0; i < len; i++) |
|
61 { |
|
62 swap_2_bytes (ptr); |
|
63 ptr += 2; |
|
64 } |
|
65 } |
|
66 |
|
67 static inline void |
|
68 swap_4_bytes (char *t, int len) |
|
69 { |
|
70 char *ptr = t; |
|
71 for (int i = 0; i < len; i++) |
|
72 { |
|
73 swap_4_bytes (ptr); |
|
74 ptr += 4; |
|
75 } |
|
76 } |
|
77 |
|
78 static inline void |
|
79 swap_8_bytes (char *t, int len) |
|
80 { |
|
81 char *ptr = t; |
|
82 for (int i = 0; i < len; i++) |
|
83 { |
|
84 swap_8_bytes (ptr); |
|
85 ptr += 8; |
|
86 } |
|
87 } |
|
88 |
|
89 #endif |
|
90 |
|
91 /* |
|
92 ;;; Local Variables: *** |
|
93 ;;; mode: C++ *** |
|
94 ;;; End: *** |
|
95 */ |