XenevaOS
Loading...
Searching...
No Matches
endian.h
Go to the documentation of this file.
1/*
2 * This file is part of LibParserUtils.
3 * Licensed under the MIT License,
4 * http://www.opensource.org/licenses/mit-license.php
5 * Copyright 2009 John-Mark Bell <jmb@netsurf-browser.org>
6 */
7
8#ifndef parserutils_endian_h_
9#define parserutils_endian_h_
10
11static inline bool endian_host_is_le(void)
12{
13 const uint16_t test = 1;
14
15 return ((const uint8_t *) &test)[0];
16}
17
18static inline uint32_t endian_swap(uint32_t val)
19{
20 return ((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) |
21 ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24);
22}
23
24static inline uint32_t endian_host_to_big(uint32_t host)
25{
26 if (endian_host_is_le())
27 return endian_swap(host);
28
29 return host;
30}
31
32static inline uint32_t endian_big_to_host(uint32_t big)
33{
34 if (endian_host_is_le())
35 return endian_swap(big);
36
37 return big;
38}
39
40#endif
unsigned int uint32_t
Definition acefiex.h:163
unsigned char uint8_t
Definition acefiex.h:161
unsigned short int uint16_t
Definition acefiex.h:162
int test
Definition p_mobj.c:45