blob: 53e32e5de83c67050925bf31751916e9cfa5a5be (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/*
* Unaligned Data Accesses -- Generic Version
*
* (c) 1998 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_UNALIGNED_H_
#define _BIRD_UNALIGNED_H_
#if CPU_NEEDS_ALIGN_WORD != 1 || CPU_NEEDS_ALIGN_LONG != 1
#include <string.h>
#endif
#if CPU_NEEDS_ALIGN_WORD == 1
#define unaligned_u16(p) (*((u16 *)(p)))
#else
static inline u16
unaligned_u16(void *p)
{
u16 x;
memcpy(&x, p, sizeof(x));
return x;
}
#endif
#if CPU_NEEDS_ALIGN_LONG == 1
#define unaligned_u32(p) (*((u32 *)(p)))
#else
static inline u32
unaligned_u32(void *p)
{
u32 x;
memcpy(&x, p, sizeof(x));
return x;
}
#endif
#endif
|