Libparserutils
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 static uint32_t magic = 0x10000002;
14
15 return (((uint8_t *) &magic)[0] == 0x02);
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{
27 return endian_swap(host);
28
29 return host;
30}
31
32static inline uint32_t endian_big_to_host(uint32_t big)
33{
35 return endian_swap(big);
36
37 return big;
38}
39
40#endif
static uint32_t endian_host_to_big(uint32_t host)
Definition endian.h:24
static bool endian_host_is_le(void)
Definition endian.h:11
static uint32_t endian_big_to_host(uint32_t big)
Definition endian.h:32
static uint32_t endian_swap(uint32_t val)
Definition endian.h:18