• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CORE_FXCRT_BYTEORDER_H_
6 #define CORE_FXCRT_BYTEORDER_H_
7 
8 #include "build/build_config.h"
9 #include "third_party/base/sys_byteorder.h"
10 
11 namespace fxcrt {
12 
13 // Converts the bytes in |x| from host order (endianness) to little endian, and
14 // returns the result.
ByteSwapToLE16(uint16_t x)15 inline uint16_t ByteSwapToLE16(uint16_t x) {
16   return pdfium::base::ByteSwapToLE16(x);
17 }
18 
ByteSwapToLE32(uint32_t x)19 inline uint32_t ByteSwapToLE32(uint32_t x) {
20   return pdfium::base::ByteSwapToLE32(x);
21 }
22 
23 // Converts the bytes in |x| from host order (endianness) to big endian, and
24 // returns the result.
ByteSwapToBE16(uint16_t x)25 inline uint16_t ByteSwapToBE16(uint16_t x) {
26 #if defined(ARCH_CPU_LITTLE_ENDIAN)
27   return pdfium::base::ByteSwap(x);
28 #else
29   return x;
30 #endif
31 }
32 
ByteSwapToBE32(uint32_t x)33 inline uint32_t ByteSwapToBE32(uint32_t x) {
34 #if defined(ARCH_CPU_LITTLE_ENDIAN)
35   return pdfium::base::ByteSwap(x);
36 #else
37   return x;
38 #endif
39 }
40 
41 }  // namespace fxcrt
42 
43 #endif  // CORE_FXCRT_BYTEORDER_H_
44