]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Main/ByteSwap.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / StdLib / LibC / Main / ByteSwap.c
CommitLineData
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
24Switches the endianness of a 16-bit integer.\r
25\r
26This function swaps the bytes in a 16-bit unsigned value to switch the value\r
27from little endian to big endian or vice versa. The byte swapped value is\r
28returned.\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
35uint16_t bswap16(uint16_t Value)\r
36{\r
37 return SwapBytes16(Value);\r
38}\r
39\r
40/**\r
41Switches the endianness of a 32-bit integer.\r
42\r
43This function swaps the bytes in a 32-bit unsigned value to switch the value\r
44from little endian to big endian or vice versa. The byte swapped value is\r
45returned.\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
52uint32_t bswap32(uint32_t Value)\r
53{\r
54 return SwapBytes32(Value);\r
55}\r
56\r
57/**\r
58Switches the endianness of a 64-bit integer.\r
59\r
60This function swaps the bytes in a 64-bit unsigned value to switch the value\r
61from little endian to big endian or vice versa. The byte swapped value is\r
62returned.\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
69uint64_t bswap64(uint64_t Value)\r
70{\r
71 return SwapBytes64(Value);\r
72}\r