libosmocore
UNKNOWN
Osmocom core library
Toggle main menu visibility
Loading...
Searching...
No Matches
byteswap.h
Go to the documentation of this file.
1
2
3
#pragma once
4
#include <stdint.h>
5
#include <
osmocom/core/endian.h
>
6
10
static
inline
uint32_t
osmo_swab32
(uint32_t in)
11
{
12
uint32_t out;
13
14
out = (in & 0xff) << 24;
15
out |= (in & 0xff00) << 8;
16
out |= (in & 0xff0000) >> 8;
17
out |= (in & 0xff000000) >> 24;
18
19
return
out;
20
}
21
25
static
inline
uint16_t
osmo_swab16
(uint16_t in)
26
{
27
uint16_t out;
28
29
out = (in & 0xff) << 8;
30
out |= (in & 0xff00) >> 8;
31
32
return
out;
33
}
34
35
#if OSMO_IS_LITTLE_ENDIAN == 1
36
#define osmo_ntohl(x) osmo_swab32(x)
37
#define osmo_ntohs(x) osmo_swab16(x)
38
#define osmo_htonl(x) osmo_swab32(x)
39
#define osmo_htons(x) osmo_swab16(x)
40
#else
41
#define osmo_ntohl(x) (x)
42
#define osmo_ntohs(x) (x)
43
#define osmo_htonl(x) (x)
44
#define osmo_htons(x) (x)
45
#endif
osmo_swab32
static uint32_t osmo_swab32(uint32_t in)
byte-swap a 32bit word
Definition
byteswap.h:10
osmo_swab16
static uint16_t osmo_swab16(uint16_t in)
byte-swap a 16bit word
Definition
byteswap.h:25
endian.h
GNU and FreeBSD have various ways to express the endianness but none of them is similar enough.
include
osmocom
core
byteswap.h
Generated by
1.17.0