]>
Commit | Line | Data |
---|---|---|
2aa62f2b | 1 | /** @file\r |
2 | Byte Swap routines for endian-nes conversions.\r | |
3 | \r | |
4 | Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials are licensed and made available under\r | |
6 | the terms and conditions of the BSD License that accompanies this distribution.\r | |
7 | The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php.\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | **/\r | |
13 | #include <Library/BaseLib.h>\r | |
14 | #include <LibConfig.h>\r | |
15 | \r | |
16 | #include <sys/bswap.h>\r | |
17 | \r | |
18 | // Undefine macro versions of the functions to be defined below.\r | |
19 | #undef bswap16\r | |
20 | #undef bswap32\r | |
21 | #undef bswap64\r | |
22 | \r | |
23 | /**\r | |
24 | Switches the endianness of a 16-bit integer.\r | |
25 | \r | |
26 | This function swaps the bytes in a 16-bit unsigned value to switch the value\r | |
27 | from little endian to big endian or vice versa. The byte swapped value is\r | |
28 | returned.\r | |
29 | \r | |
30 | @param Value A 16-bit unsigned value.\r | |
31 | \r | |
32 | @return The byte swapped Value.\r | |
33 | \r | |
34 | **/\r | |
35 | uint16_t bswap16(uint16_t Value)\r | |
36 | {\r | |
37 | return SwapBytes16(Value);\r | |
38 | }\r | |
39 | \r | |
40 | /**\r | |
41 | Switches the endianness of a 32-bit integer.\r | |
42 | \r | |
43 | This function swaps the bytes in a 32-bit unsigned value to switch the value\r | |
44 | from little endian to big endian or vice versa. The byte swapped value is\r | |
45 | returned.\r | |
46 | \r | |
47 | @param Value A 32-bit unsigned value.\r | |
48 | \r | |
49 | @return The byte swapped Value.\r | |
50 | \r | |
51 | **/\r | |
52 | uint32_t bswap32(uint32_t Value)\r | |
53 | {\r | |
54 | return SwapBytes32(Value);\r | |
55 | }\r | |
56 | \r | |
57 | /**\r | |
58 | Switches the endianness of a 64-bit integer.\r | |
59 | \r | |
60 | This function swaps the bytes in a 64-bit unsigned value to switch the value\r | |
61 | from little endian to big endian or vice versa. The byte swapped value is\r | |
62 | returned.\r | |
63 | \r | |
64 | @param Value A 64-bit unsigned value.\r | |
65 | \r | |
66 | @return The byte swapped Value.\r | |
67 | \r | |
68 | **/\r | |
69 | uint64_t bswap64(uint64_t Value)\r | |
70 | {\r | |
71 | return SwapBytes64(Value);\r | |
72 | }\r |