]> git.draconx.ca Git - liblbx.git/blob - src/byteorder.h
liblbx: Remove exact-width integer types from lbx_state.
[liblbx.git] / src / byteorder.h
1 #ifndef BYTEORDER_H_
2 #define BYTEORDER_H_
3
4 #ifdef HAVE_CONFIG_H
5 #       include "config.h"
6 #endif
7
8 #include <stdint.h>
9
10 static inline uint16_t _flip16(uint16_t val)
11 {
12         uint16_t hostval;
13         int i;
14
15         for (i = 0; i < sizeof val; i++)
16                 ((uint8_t *)&hostval)[i] = ((uint8_t *)&val)[sizeof val - i];
17 }
18
19 static inline uint32_t _flip32(uint32_t val)
20 {
21         uint32_t hostval;
22         int i;
23
24         for (i = 0; i < sizeof val; i++)
25                 ((uint8_t *)&hostval)[i] = ((uint8_t *)&val)[sizeof val - i];
26 }
27
28 #ifdef WORDS_BIGENDIAN
29 #       define letohs(x) _flip16(x)
30 #       define letohl(x) _flip32(x)
31 #else
32 #       define letohs(x) ((uint16_t)(x))
33 #       define letohl(x) ((uint16_t)(x))
34 #endif
35
36 #endif