diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2008-07-11 15:50:46 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2008-07-11 15:50:46 +0000 |
commit | 14c7f45cdae826f88dc539c8c38dd95caf305731 (patch) | |
tree | 832da054b7cfb2dc6fd63339af736625f31d21aa /utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/endianness.c | |
parent | 7c84ede3781c27db73403bd6302f320c76a58c8c (diff) | |
download | rockbox-14c7f45cdae826f88dc539c8c38dd95caf305731.tar.gz rockbox-14c7f45cdae826f88dc539c8c38dd95caf305731.zip |
Add zook's ZenUtils to SVN
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18010 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/endianness.c')
-rwxr-xr-x | utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/endianness.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/endianness.c b/utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/endianness.c new file mode 100755 index 0000000000..8a0999b63e --- /dev/null +++ b/utils/zenutils/libraries/beecrypt-4.1.2/beecrypt/endianness.c | |||
@@ -0,0 +1,94 @@ | |||
1 | /* | ||
2 | * Copyright (c) 1998, 1999, 2000, 2001 Virtual Unlimited B.V. | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; if not, write to the Free Software | ||
16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | /*!\file endianness.c | ||
21 | * \brief Endian-dependant encoding/decoding. | ||
22 | * \author Bob Deblier <bob.deblier@pandora.be> | ||
23 | */ | ||
24 | |||
25 | #define BEECRYPT_DLL_EXPORT | ||
26 | |||
27 | #if HAVE_CONFIG_H | ||
28 | # include "config.h" | ||
29 | #endif | ||
30 | |||
31 | #if HAVE_ENDIAN_H && HAVE_ASM_BYTEORDER_H | ||
32 | # include <endian.h> | ||
33 | #endif | ||
34 | |||
35 | #include "beecrypt/endianness.h" | ||
36 | |||
37 | #undef swap16 | ||
38 | #undef swapu16 | ||
39 | #undef swap32 | ||
40 | #undef swapu32 | ||
41 | #undef swap64 | ||
42 | #undef swapu64 | ||
43 | |||
44 | int16_t swap16(int16_t n) | ||
45 | { | ||
46 | return ( ((n & 0xff) << 8) | | ||
47 | ((n & 0xff00) >> 8) ); | ||
48 | } | ||
49 | |||
50 | uint16_t swapu16(uint16_t n) | ||
51 | { | ||
52 | return ( ((n & 0xffU) << 8) | | ||
53 | ((n & 0xff00U) >> 8) ); | ||
54 | } | ||
55 | |||
56 | int32_t swap32(int32_t n) | ||
57 | { | ||
58 | return ( ((n & 0xff) << 24) | | ||
59 | ((n & 0xff00) << 8) | | ||
60 | ((n & 0xff0000) >> 8) | | ||
61 | ((n & 0xff000000) >> 24) ); | ||
62 | } | ||
63 | |||
64 | uint32_t swapu32(uint32_t n) | ||
65 | { | ||
66 | return ( ((n & 0xffU) << 24) | | ||
67 | ((n & 0xff00U) << 8) | | ||
68 | ((n & 0xff0000U) >> 8) | | ||
69 | ((n & 0xff000000U) >> 24) ); | ||
70 | } | ||
71 | |||
72 | int64_t swap64(int64_t n) | ||
73 | { | ||
74 | return ( ((n & (((int64_t) 0xff) )) << 56) | | ||
75 | ((n & (((int64_t) 0xff) << 8)) << 40) | | ||
76 | ((n & (((int64_t) 0xff) << 16)) << 24) | | ||
77 | ((n & (((int64_t) 0xff) << 24)) << 8) | | ||
78 | ((n & (((int64_t) 0xff) << 32)) >> 8) | | ||
79 | ((n & (((int64_t) 0xff) << 40)) >> 24) | | ||
80 | ((n & (((int64_t) 0xff) << 48)) >> 40) | | ||
81 | ((n & (((int64_t) 0xff) << 56)) >> 56) ); | ||
82 | } | ||
83 | |||
84 | uint64_t swapu64(uint64_t n) | ||
85 | { | ||
86 | return ( ((n & (((uint64_t) 0xff) )) << 56) | | ||
87 | ((n & (((uint64_t) 0xff) << 8)) << 40) | | ||
88 | ((n & (((uint64_t) 0xff) << 16)) << 24) | | ||
89 | ((n & (((uint64_t) 0xff) << 24)) << 8) | | ||
90 | ((n & (((uint64_t) 0xff) << 32)) >> 8) | | ||
91 | ((n & (((uint64_t) 0xff) << 40)) >> 24) | | ||
92 | ((n & (((uint64_t) 0xff) << 48)) >> 40) | | ||
93 | ((n & (((uint64_t) 0xff) << 56)) >> 56) ); | ||
94 | } | ||